<template>
    <div class="collectionchannel">
        <!-- 采集通道IstransChannel:0 -->
        <div class="con">
            <div class="con-left">
                    <el-scrollbar style="height:calc(100% - 5px);width: 100%;">
                    <el-tree class="filter-tree" :data="dataList"  
                        :expand-on-click-node="true" 
                         default-expand-all
                        :props="defaultProps" :highlight-current='true'  ref="tree" @node-click="leftnodeClick"
                        node-key='myid'
                    >
                    <template #default="{ node }">
                        <div class="custom-tree-node">
                            <div class="flexitem">
                                 <img src="../assets/btnImg/2.0.png" alt="" v-if="node.data.level == 1">
                                 <img src="../assets/btnImg/2.1.png" alt="" v-if="node.data.level == 3">
                                 <img src="../assets/btnImg/group.png" alt="" v-if="node.data.level == 2">
                                 {{ node.label }}
                            </div>
                            <i class="el-icon-more" v-show="node.data.level == '3'"  @click.stop="onRightClick($event,node.data)"></i>
                        </div>
                    </template>
                    </el-tree>
                    </el-scrollbar>
                    <!-- 节点操作 -->
                    <div class="nodeoperation"  v-show="nodeFlag"  :style="{'top':mymouseY+'px','left':mymouseX+'px'}" @mouseleave="nodeFlag = false">
                            <!-- <div v-show="mylevel == 1" @click="addChannel">添加通道</div>
                            <div v-show="mylevel == 2" @click="addDevices">添加设备</div>
                            <div v-show="mylevel == 2" style="margin-top: 10px;" @click="delChannel">删除通道</div> -->
                            <div v-show="mylevel == 3" @click="delDevices2">删除设备</div>
                    </div>
            </div>
            <div class="con-right-all" v-show="leftLevel == 11000">
                      <div class="con-bottom">
                    <div class="bottomoperate-btn solidcolor" @click='getAgreementListfn'>转发类型</div>
                    <!-- <div class="bottomoperate-btn bordercolor">导入</div>
                    <div class="bottomoperate-btn bordercolor" @click="exportDataExcel">导出</div>
                    <div class="bottomoperate-btn bordercolor teshubtn">导出模板专用</div> -->
                 </div>
            </div>
            <!-- 转发类型 -->
            <div class="con-right-all" v-show="leftLevel == 1">
                 <div class="xieyililist">
                       <div class="topdisflex">
                           <div class="mytitle">
                                <span></span>转发类型列表
                            </div>
                           <div>
                                <el-button  @click="addChannel" type="primary">添加通道</el-button>
                                <el-button  @click="openAgreementType('添加转发类型')" type="primary">添加转发类型</el-button>
                                <el-button  class="last-el-button" @click="getAgreementListfn" type="primary" plain>转发协议</el-button>
                           </div>
                       </div>
                     <div class="mytable">
                         <el-table :data="TypeTable" max-height="100%" stripe  style="width: 100%;" >
                                        <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
                                        <el-table-column prop="number" width="100" label="编号"> </el-table-column>
                                        <el-table-column prop="name" label="转发类型名称"> </el-table-column>
                                        <el-table-column prop="start_point" label="起始点号(偏移量)" width="200"> </el-table-column>
                                        <el-table-column prop="remark" label="操作" width="200" align="center"> 
                                            <template #default="{row}">
                                                <!--  -->
                                                <div class="table-img">
                                                     <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                                                             <img src="../assets/btnImg/edit2.png" alt="" @click="openAgreementType('修改转发类型',row)">
                                                        </el-tooltip>
                                                        <el-tooltip class="item" effect="dark" content="删除" placement="top">
                                                             <img src="../assets/btnImg/del2.png" style="margin-left:20px" @click="delAgreementtype(row)">
                                                        </el-tooltip>  
                                                </div>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                     </div>
                 </div>
            </div>
           
            <!-- 通道信息 isDdevice-->
            <div class="con-right-all" v-show="leftLevel == 2">
                   <div class="xieyililist">
                       <div class="topdisflex">
                        <div class="mytitle">
                                <span></span>通道信息
                            </div>
                           <div>
                               <el-button type="primary"  @click="editChannel">编辑通道</el-button>
                               <el-button type="danger" class="last-el-button" @click="delChannel">删除通道</el-button>
                           </div>
                       </div>
                     <div class="channelinfobox">
                         <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">通道号：</div>
                                <div class="elinputdisabled">{{channelInfo.channel_number}}</div>
                            </div>
                             <div class="items itemright">
                                <div class="leftname">通道名称：</div>
                                <div class="elinputdisabled">{{channelInfo.channel_name}}</div>
                            </div>
                             <div class="items itemright">
                                <div class="leftname">通道类型：</div>
                                <el-select v-model="channelInfo.channel_type" placeholder="请输入通道类型" style="width:100%" disabled> 
                                                <el-option
                                                   v-for="item in thoroughfareOptionType"
                                                   :key="item.value"
                                                   :label="item.label"
                                                   :value="item.value">
                                                   </el-option>
                                             </el-select>
                            </div>
                            <div class="items">
                                <div class="leftname">通道规约：</div>
                                 <el-select v-model="channelInfo.channel_protocol" placeholder="请选择通道规约" style="width:100%" disabled>
                                                      <el-option
                                                        v-for="item in thoroughfareOptionStatute"
                                                        :key="item.id"
                                                        :label="item.protocol_alias == '' ? item.name : item.protocol_alias"
                                                        :value="item.id">
                                                        </el-option>
                                                  </el-select>
                            </div>
                         </div>
                         <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">端口类型：</div>
                                <div class="elinputdisabled" v-if="portType == 1">串口</div>
                                <div class="elinputdisabled" v-if="portType == 2">TCP服务端</div>
                                <div class="elinputdisabled" v-if="portType == 3">TCP客户端</div>
                                <!-- <div class="elinputdisabled" v-if="portType == 4">MQTT客户端</div>
                                <div class="elinputdisabled" v-if="portType == 5">UDP客户端</div>
                                <div class="elinputdisabled" v-if="portType == 6">CAN</div> -->
                                <div class="elinputdisabled" v-if="portType == 7">DI</div>
                                <div class="elinputdisabled" v-if="portType == 8">DO</div>
                                <!-- <div class="elinputdisabled" v-if="portType == 0">无</div> -->
                            </div>
                           
                             <div class="items itemright">
                                <div class="leftname">发送间隔：</div>
                                <div class="elinputdisabled">{{channelInfo.channel_interval}}</div>
                            </div>
                              <div class="items itemright">
                               <div class="leftname">通道设置：</div>
                                <el-checkbox v-model="auto_open"></el-checkbox>
                                <span class="tong" style="margin-left:4px">通道自动打开</span>
                            </div>
                            <div class="items">
                               
                            </div>
                         </div>
                        <!-- 串口 -->
                        <div class="body-items" v-if="portType == 1">
                          <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">串口号：</div>
                               <el-select v-model="channelInfo.serial_number" disabled>
                                                <el-option
                                                      v-for="item in serial_numberList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                 </el-select>
                            </div>
                             <div class="items itemright">
                                <div class="leftname">奇偶校验：</div>
                               <el-select v-model="channelInfo.parity" disabled>
                                                <el-option
                                                      v-for="item in ParityOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                            </div>
                            <div class="items itemright">
                                <div class="leftname">停止位：</div>
                                 <el-select v-model="channelInfo.stop_bits" disabled>
                                                <el-option
                                                      v-for="item in stopBitsOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                            </div>
                            <div class="items">
                                <div class="leftname">波特率：</div>
                                 <el-select v-model="channelInfo.baud_rate" disabled>
                                                <el-option
                                                      v-for="item in BAUDOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                            </div>
                         </div>
                         <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname ">数据位：</div>
                                <el-select v-model="channelInfo.data_bits" disabled>
                                                <el-option
                                                      v-for="item in dataBitsOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                            </div>
                             <div class="items itemright">
                               
                            </div>
                            <div class="items itemright">
                               
                            </div>
                            <div class="items">
                               
                            </div>
                           
                         </div>
                        </div>
                        <!-- TPC服务端 -->
                        <div class="body-items" v-if="portType == 2">
                          <div class="infoitems">
                            
                             <div class="items itemright">
                                <div class="leftname">本机地址：</div>
                                <el-input v-model="channelInfo.local_address" placeholder="[IP地址格式]" disabled></el-input>
                            </div>
                             <div class="items itemright">
                                <div class="leftname">本机端口：</div>
                                <el-input v-model="channelInfo.local_port" placeholder="[整型数字]" disabled></el-input>
                            </div>
                            <div class="items itemright">
                                <div class="leftname">远方地址：</div>
                                <el-input v-model="channelInfo.remote_address" placeholder="[IP地址格式]" disabled></el-input>
                            </div>
                            <div class="items">
                               
                            </div>
                            <!-- <div class="items">
                                <div class="leftname">遥控设置：</div>
                               <el-checkbox v-model="checked"></el-checkbox>
                              <span class="tong" style="margin-left:4px">允许遥控</span>
                            </div> -->
                         </div>
                        </div>
                        <!-- TPC客户端 -->
                        <div class="body-items" v-if="portType == 3">
                          <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">远方端口：</div>
                                <el-input v-model="channelInfo.remote_port" placeholder="[整型数字]" disabled></el-input>
                            </div>
                             <div class="items itemright">
                                <div class="leftname ">远方地址：</div>
                                <el-input v-model="channelInfo.remote_address" placeholder="[IP地址格式]" disabled></el-input>
                            </div>
                             <div class="items itemright">
                               
                            </div>
                            <div class="items">
                               
                            </div>
                           
                         </div>
                        </div>
                        <!-- MQTT客户端 -->
                        <div class="body-items" v-if="portType == 4">
                           <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">远程端口：</div>
                                <el-input v-model="channelInfo.aaaa" placeholder="[整型数字]" disabled></el-input>
                            </div>
                             <div class="items itemright">
                                <div class="leftname">远程地址：</div>
                                <el-input v-model="channelInfo.aaaa" placeholder="[IP地址格式]" disabled></el-input>
                            </div>
                            <div class="items itemright">
                                <div class="leftname">客户机标识：</div>
                                <el-input v-model="channelInfo.aaaa" placeholder="请输入客户机标识" disabled></el-input>
                            </div>
                             <div class="items">
                                <div class="leftname">发布主题：</div>
                                <el-input v-model="channelInfo.aaaa" placeholder="请输入发布主题" disabled></el-input>
                            </div>
                            </div>
                            <div class="infoitems">
                                
                                <div class="items itemright">
                                    <div class="leftname ">用户名：</div>
                                    <el-input v-model="channelInfo.aaaa" placeholder="请输入用户名" disabled></el-input>
                                </div>
                                <div class="items itemright">
                                    <div class="leftname ">密码：</div>
                                    <el-input v-model="channelInfo.aaaa" placeholder="请输入密码" disabled></el-input>
                                </div>
                                <div class="items itemright">
                                    <div class="leftname">订阅：</div>
                                    <el-input v-model="channelInfo.aaaa" placeholder="请输入发布主题" disabled></el-input>
                                </div>
                                <div class="items">

                                </div>
                            
                            </div>
                        </div>
                        <!-- DI -->
                        <div class="body-items" v-if="portType == 7">
                          <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">DI口：</div>
                                <el-input v-model="channelInfo.di_number" placeholder="DI口" disabled></el-input>
                            </div>
                             <div class="items itemright">
                                
                            </div>
                             <div class="items itemright">
                               
                            </div>
                            <div class="items">
                               
                            </div>
                           
                         </div>
                        </div>
                        <!-- DO -->
                        <div class="body-items" v-if="portType == 8">
                          <div class="infoitems">
                             <div class="items itemright">
                                <div class="leftname">DO口：</div>
                                <el-input v-model="channelInfo.do_number" placeholder="DO口" disabled></el-input>
                            </div>
                             <div class="items itemright">
                            </div>
                             <div class="items itemright">
                               
                            </div>
                            <div class="items">
                               
                            </div>
                           
                         </div>
                        </div>
                         
                     </div>
                     <div class="topdisflex">
                           <div class="mytitle">
                                <span></span>通道设备列表
                            </div>
                           <div>
                                <el-button type="primary" class="last-el-button" @click="addDecivefn">添加设备</el-button>
                           </div>
                       </div>
                     <div class="mytable" style="height:calc(100% - 245px)">
                        <el-table :data="deviceList" max-height="100%" stripe  style="width: 100%;" >
                                        <el-table-column type='index'  width="60" label="序号" align="center"> </el-table-column>
                                        <el-table-column prop="device_name"  width="120" label="设备名称"> </el-table-column>
                                        <el-table-column prop="device_number"  width="80" label="设备号"> </el-table-column>
                                        <el-table-column prop="device_address" width="120" label="设备地址"> </el-table-column>
                                        <el-table-column prop="device_addressex" width="120" label="扩展地址"> </el-table-column>
                                        <el-table-column prop="device_group_name" width="90" label="设备组"> </el-table-column>
                                        <el-table-column prop="device_template_name" width="180" label="设备模板"> </el-table-column>
                                        <el-table-column prop="device_serial_type_name" width="120" label="设备子系列"> </el-table-column>
                                        <el-table-column prop="device_protocol_name" width="180" label="设备规约"> </el-table-column>
                                        <el-table-column prop="break_count" width="90" label="中断次数"> </el-table-column>
                                        <el-table-column prop="resend_count" width="90" label="重发次数"> </el-table-column>
                                        <el-table-column  width="90" label="是否投运" align="center"> 
                                             <template #default="{row}">
                                                    <div class="mysort">
                                                      {{row.run ? '是' :'否'}}
                                                    </div>
                                                </template>
                                        </el-table-column>
                                        <el-table-column  width="180" label="操作" fixed="right" align="center"> 
                                            <!-- #default="{row}" -->
                                             <template #default="{row}">
                                                    <div class="mysort">
                                                        <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                                                             <img src="../assets/btnImg/edit2.png" alt="" style="margin:0px 26px" @click="editDevice(row)">
                                                        </el-tooltip>
                                                        <el-tooltip class="item" effect="dark" content="删除" placement="top">
                                                          <img src="../assets/btnImg/del2.png" alt="" @click="delDevices(row)">
                                                        </el-tooltip>
                                                    </div>
                                                </template>
                                        </el-table-column>
                      </el-table>
                     </div>
                 </div>
            </div>
          
            <!-- 设备信息 -->
            <div class="con-right-all" v-show="leftLevel == 3">
                        <div class="dev-right-top">
                            <!-- rowDevItem = item -->
                            <div :class="['top-item', {'active':item == rowDevItem}]" v-for="(item,index) in deviceItem" :key="index" @click="rowDevItemfn(item)">{{item}}</div>
                        </div>
                        <!-- 设备信息 -->
                        <div class="right-content"  v-if="rowDevItem == '设备信息'" style="margin-top:20px">
                            <div class="content-left">
                                <div class="content-item">
                                    <div class="item-name teshu">设备名称</div>
                                    <div class="item-input">
                                        <el-input v-model="deviceInfo.device_name"  placeholder="请输入设备名称"></el-input>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                                <div class="content-item">
                                    <div class="item-name ">扩展地址</div>
                                    <div class="item-input">
                                         <el-input v-model="deviceInfo.device_addressex"  placeholder="请输入扩展地址"></el-input>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">设备组</div>
                                    <div class="item-input">
                                        <el-select v-model="deviceInfo.device_group" placeholder="请选择设备组" @change="getDeviceMuban(deviceInfo.device_group,'手动')" style="width: 100%">
                                                <el-option
                                                v-for="item in deviceGroupList"
                                                :key="item.id"
                                                :label="item.channelName"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">设备子模板</div>
                                    <div class="item-input">
                                        <el-select v-model="deviceInfo.device_template" placeholder="请选择设备子模板" @change="getDeviceTempSerialList(deviceInfo.device_template,'手动')" style="width: 100%">
                                                <el-option
                                                v-for="item in deviceTemList"
                                                :key="item.id"
                                                :label="item.channelName"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">设备子系列</div>
                                    <div class="item-input">
                                        <el-select v-model="deviceInfo.device_serial_type" placeholder="请选择设备子系列" style="width: 100%">
                                                <el-option
                                                v-for="item in deviceSubSeriesList"
                                                :key="item.id"
                                                :label="item.serial_name"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">设备规约</div>
                                    <div class="item-input">
                                        <el-select v-model="deviceInfo.device_protocol" style="width: 100%">
                                                <el-option
                                                v-for="item in thoroughfareOptionStatute"
                                                :key="item.id"
                                                :label="item.name"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                            </div>
                            <div class="content-right">
                                <div class="content-item">
                                    <div class="item-name ">设备地址</div>
                                    <div class="item-input">
                                        <el-input v-model="deviceInfo.device_address"  placeholder="请输入设备地址"></el-input>
                                    </div>
                                     <div class="tips">[1-255数字]</div>
                                </div>
                                <div class="content-item teshuinput">
                                    <div class="item-name ">设备序号</div>
                                    <div class="item-input ">
                                        <el-input v-model="deviceInfo.device_number"  placeholder="请输入设备序号" disabled></el-input>
                                    </div>
                                    <div class="tips" style="color:transparent">[1-255数字]</div>
                                </div>
                                <div class="content-item teshuinput">
                                    <div class="item-name ">中断次数</div>
                                    <div class="item-input">
                                        <el-input v-model="deviceInfo.break_count"  placeholder="请输入中断次数"></el-input>
                                    </div>
                                     <div class="tips">[1 - 10数字]</div>
                                </div>
                                <div class="content-item teshuinput">
                                    <div class="item-name ">重发次数</div>
                                    <div class="item-input">
                                        <el-input v-model="deviceInfo.resend_count"  placeholder="请输入重发次数"></el-input>
                                    </div>
                                     <div class="tips">[1 - 10数字]</div>
                                </div>
                                 <div class="content-item">
                                                <div class="item-name ">设备投运</div>
                                                <div class="item-input">
                                                    <el-checkbox v-model="deviceInfo.run"></el-checkbox>
                                                </div>
                                   </div>
                                    <!-- <div class="content-item">
                                                <div class="item-name ">MQTT设备</div>
                                                <div class="item-input">
                                                    <el-checkbox v-model="deviceInfo.mqtt"></el-checkbox>
                                                </div>
                                   </div> -->
                                    <div class="content-item">
                                                <div class="item-name ">重新生成变量</div>
                                                <div class="item-input">
                                                    <el-checkbox v-model="mychange"></el-checkbox>
                                                </div>
                                   </div>
                                   <div class="content-item" v-show="false">
                                                <div class="item-name ">更新转换系数</div>
                                                <div class="item-input">
                                                    <el-checkbox v-model="checked"></el-checkbox>
                                                </div>
                                   </div>
                            </div>
                        </div>
                        <!-- Modbus扩展参数 -->
                         <div class="right-content right-parameter" v-if="rowDevItem == '扩展参数' && deviceInfo.devType == 3">
                            <div class="content-left">
                                <div class="parameter-top">Modbus子站参数/起始点号</div>
                                <div class="content-item">
                                    <div class="item-name">读线圈状态(DO)</div>
                                    <div class="item-input">
                                        <el-input v-model="ExtendedParametersModbus.channelId"  placeholder="请输入"></el-input>
                                    </div>
                                </div>
                                <div class="content-item">
                                    <div class="item-name ">读输入状态(DI)</div>
                                    <div class="item-input">
                                         <el-input v-model="ExtendedParametersModbus.channelId"  placeholder="请输入"></el-input>
                                    </div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">读寄读器(遥测)</div>
                                    <div class="item-input">
                                         <el-input v-model="ExtendedParametersModbus.channelId"  placeholder="请输入"></el-input>
                                    </div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">读保持寄存器(电量)</div>
                                    <div class="item-input">
                                         <el-input v-model="ExtendedParametersModbus.channelId"  placeholder="请输入"></el-input>
                                    </div>
                                </div>
                                 <div class="content-item">
                                    <div class="item-name ">写线圈(遥控)</div>
                                    <div class="item-input">
                                         <el-input v-model="ExtendedParametersModbus.channelId"  placeholder="请输入"></el-input>
                                    </div>
                                </div>
                                  <div class="content-item">
                                    <div class="item-name ">写寄存器(设定值)</div>
                                    <div class="item-input">
                                         <el-input v-model="ExtendedParametersModbus.channelId"  placeholder="请输入"></el-input>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- 104扩展参数 -->
                       <div class="con2" v-if="rowDevItem == '扩展参数' && deviceInfo.devType == 2">
                                <div>
                                    <div class="con2-titile">104子站参数</div>
                                    <div class="shezhi-item">
                                        <div class="left-input">
                                        <div class="less-name">公共地址：</div>
                                        <el-input v-model="ExtendedParameters104.public_address" placeholder="请输入"></el-input>

                                        </div>
                                        <div class="right-input">
                                        <div class="less-name">缺省的遥信门限值(%)：</div>
                                        <el-input v-model="ExtendedParameters104.gate_limit" placeholder="请输入"></el-input>
                                        </div>
                                    </div>
                                    <div class="con2-titile xiaoti">起始点号<span></span></div>
                                    <div class="con2-item ttttt">
                                        <div class="item-left">版本：</div>
                                         <el-select v-model="ExtendedParameters104.version" placeholder="版本" style="width:100px">
                                                <el-option
                                                v-for="item in versionList"
                                                :key="item.id"
                                                :label="item.channelName"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                        <div class="item-left">遥信：</div>
                                        <el-input v-model="ExtendedParameters104.point_yx"  style="width:100px"></el-input>
                                        <div class="item-left">遥测：</div>
                                        <el-input v-model="ExtendedParameters104.point_yc"  style="width:100px"></el-input>
                                        <div class="item-left">遥控：</div>
                                        <el-input v-model="ExtendedParameters104.point_yk"  style="width:100px"></el-input>
                                        
                                       
                                    </div>
                                     <div class="con2-item ttttt">
                                        <div class="item-left">参数：</div>
                                        <el-input v-model="ExtendedParameters104.point_param"  style="width:100px"></el-input>
                                        <div class="item-left">设定值：</div>
                                        <el-input v-model="ExtendedParameters104.point_setting"  style="width:100px"></el-input>
                                        <div class="item-left">电量：</div>
                                        <el-input v-model="ExtendedParameters104.point_elect_level"  style="width:100px"></el-input>
                                        <div class="item-left">分接头信息：</div>
                                        <el-input v-model="ExtendedParameters104.point_fjt"  style="width:100px"></el-input>
                                    </div>
                                     <div class="con2-titile xiaoti">超时参数<span></span></div>
                                    <div class="con2-item ttttt">
                                        <div class="item-left">t0：</div>
                                        <el-input v-model="ExtendedParameters104.t0"  style="width:60px"></el-input>
                                        <span>(秒) 连接建立的超时</span>
                                        <div class="item-left" style="width:182px">t1：</div>
                                        <el-input v-model="ExtendedParameters104.t1"  style="width:60px"></el-input>
                                        <span>(秒) 发送或测试APDU的超时</span>
                                        
                                    </div>
                                     <div class="con2-item ttttt">
                                        <div class="item-left">t2：</div>
                                        <el-input v-model="ExtendedParameters104.t2"  style="width:60px"></el-input>
                                        <span>(秒) 无数据报文t2 {{ '<' }} t1时确认的超时</span>
                                        <div class="item-left">t3：</div>
                                        <el-input v-model="ExtendedParameters104.t3"  style="width:60px"></el-input>
                                        <span>(秒) 长期空闲t3 > t1状态下发送测试帧的超时</span>
                                    </div>
                                     <div class="con2-item ttttt">
                                        <div class="item-left">t4：</div>
                                        <el-input v-model="ExtendedParameters104.t4"  style="width:60px"></el-input>
                                        <span>(秒) 应用报文确认超时</span>
                                    </div>
                                     <div class="con2-titile xiaoti">I格式APDU的数据参数<span></span></div>
                                      <div class="con2-item ttttt">
                                        <div class="item-left">k：</div>
                                        <el-input v-model="ExtendedParameters104.k"  style="width:60px"></el-input>
                                        <span>APDUs 发送状态变量的最大不同接收序号</span>
                                        <div class="item-left" style="width: 65px;">w：</div>
                                        <el-input v-model="ExtendedParameters104.w"  style="width:60px"></el-input>
                                        <span>APDUs 接送到w个I格式APDU后的最后确认</span>
                                    </div>
                                    <div class="con2-item">
                                        <div class="item-left">测量值(遥测)传输类型：</div>
                                        <el-radio v-model="ExtendedParameters104.yc_tran_type" label="1">规一化值</el-radio>
                                        <el-radio v-model="ExtendedParameters104.yc_tran_type" label="2">标度化值</el-radio>
                                        <el-radio v-model="ExtendedParameters104.yc_tran_type" label="3">短浮点数</el-radio>
                                    </div>
                                    <div class="con2-item">
                                        <div class="item-left">遥信传输类型：</div>
                                        <el-radio v-model="ExtendedParameters104.yx_tran_type" label="1">单点遥信</el-radio>
                                        <el-radio v-model="ExtendedParameters104.yx_tran_type" label="2">双点遥信</el-radio>
                                    </div>
                                </div>
                        </div>

                        <!-- 101扩展参数 -->
                       <div class="con2" v-if="rowDevItem == '扩展参数' && deviceInfo.devType == 1">
                                <div>
                                    <div class="con2-titile">101子站参数</div>
                                    <div class="shezhi-item">
                                        <div class="left-input">
                                        <div class="less-name">ASDU公共地址：</div>
                                        <el-input v-model="ExtendedParameters101.public_address" placeholder="请输入"></el-input>

                                        </div>
                                        <div class="right-input">
                                        <div class="less-name">缺省的遥信门限值(%)：</div>
                                        <el-input v-model="ExtendedParameters101.gate_limit" placeholder="请输入"></el-input>
                                        </div>
                                    </div>
                                    <div class="con2-titile xiaoti">起始点号<span></span></div>
                                    <div class="con2-item ttttt">
                                        <div class="item-left">版本：</div>
                                         <el-select v-model="ExtendedParameters101.version" placeholder="版本" style="width:100px">
                                                <el-option
                                                v-for="item in versionList"
                                                :key="item.id"
                                                :label="item.channelName"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                        <div class="item-left">遥信：</div>
                                        <el-input v-model="ExtendedParameters101.point_yx"  style="width:100px"></el-input>
                                        <div class="item-left">遥测：</div>
                                        <el-input v-model="ExtendedParameters101.point_yc"  style="width:100px"></el-input>
                                        <div class="item-left">遥控：</div>
                                        <el-input v-model="ExtendedParameters101.point_yk"  style="width:100px"></el-input>
                                        
                                       
                                    </div>
                                     <div class="con2-item ttttt">
                                        <div class="item-left">参数：</div>
                                        <el-input v-model="ExtendedParameters101.point_param"  style="width:100px"></el-input>
                                        <div class="item-left">设定值：</div>
                                        <el-input v-model="ExtendedParameters101.point_setting"  style="width:100px"></el-input>
                                        <div class="item-left">电量：</div>
                                        <el-input v-model="ExtendedParameters101.point_elect_level"  style="width:100px"></el-input>
                                        <div class="item-left">分接头信息：</div>
                                        <el-input v-model="ExtendedParameters101.point_fjt"  style="width:100px"></el-input>
                                    </div>
                                  
                                    <div class="con2-item">
                                        <div class="item-left">测量值(遥测)传输类型：</div>
                                        <el-radio v-model="ExtendedParameters101.yc_tran_type" label="1">规一化值</el-radio>
                                        <el-radio v-model="ExtendedParameters101.yc_tran_type" label="2">标度化值</el-radio>
                                        <el-radio v-model="ExtendedParameters101.yc_tran_type" label="3">短浮点数</el-radio>
                                    </div>
                                    <div class="con2-item">
                                        <div class="item-left">遥信传输类型：</div>
                                        <el-radio v-model="ExtendedParameters101.yx_tran_type" label="1">单点遥信</el-radio>
                                        <el-radio v-model="ExtendedParameters101.yx_tran_type" label="2">双点遥信</el-radio>
                                    </div>
                                    <div class="con2-item">
                                        <div class="item-left">平衡式传输：</div>
                                          <el-checkbox v-model="ExtendedParameters101.balance"></el-checkbox>
                                    </div>
                                </div>
                        </div>
                        <!-- 101扩展参数CDT -->
                       <div class="con2" v-if="rowDevItem == '扩展参数' && deviceInfo.devType == 4">
                                <div>
                                    <div class="con2-titile">101子站参数</div>
                                    <div class="shezhi-item">
                                        <div class="left-input">
                                        <div class="less-name">主站地址：</div>
                                        <el-input v-model="ExtendedParametersCDT.info" placeholder="请输入"></el-input>

                                        </div>
                                        <div class="right-input">
                                        <div class="less-name">子站地址：</div>
                                        <el-input v-model="ExtendedParametersCDT.info" placeholder="请输入"></el-input>
                                        </div>
                                    </div>
                                    <div class="con2-titile xiaoti">起始点号<span></span></div>
                                    <div class="con2-item ttttt">
                                        <div class="item-left">重要遥测：</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                        <div class="item-left">次要遥测：</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                        <div class="item-left">一般遥测：</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                       
                                    </div>
                                     <div class="con2-item ttttt">
                                        <div class="item-left">遥信：</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                        <div class="item-left">电量：</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                        <div class="item-left">遥控</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                    </div>
                                  
                                    <div class="con2-item">
                                        <div class="item-left">同步字：</div>
                                        <el-input v-model="ExtendedParametersCDT.info"  style="width:100px"></el-input>
                                    </div>
                                </div>
                        </div>
                        <!-- 其他 -->
                        <div class="other-con" v-if="rowDevItem != '扩展参数' && rowDevItem != '设备信息'">
                              <div class="other-left">
                                    <div class="other-type">采集变量</div>
                                    <div class="other-tree">
                                      <el-scrollbar height="100%">
                                            <el-tree class="filter-tree" :data="gatherDataList"  
                                                :expand-on-click-node="true" 
                                                node-key="myid" :props="collectDefaultProps" :highlight-current='true'  ref="tree" 
                                                @node-click='treeClick'
                                            >
                                            <template #default="{ node }">
                                                <div class="custom-tree-node" >
                                                    <div class="flexitem">
                                                        <img src="../assets/btnImg/2.1.png" alt="" v-if="node.data.mytype == 'device'">
                                                        <img src="../assets/btnImg/group.png" alt="" v-else>
                                                        {{ node.label }}
                                                    </div>
                                                </div>
                                            </template>
                                            </el-tree>
                                       </el-scrollbar>
                                    </div>
                              </div>
                              <div class="other-right">
                                <!-- 初始表格 -->
                              <div class="initial-table">
                                     <div class="mytablemy">
                                        <el-table :data="collecVariablTable" height="100%" stripe  style="width: 100%;" ref="multipleTable" border @selection-change="handleSelectionChange">
                                         <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
                                         <el-table-column type="selection" width="55" align="center" :selectable="checkSelectable"> </el-table-column>
                                        <el-table-column prop="fullName" label="变量名称"> </el-table-column>
                                      </el-table>
                                     </div>
                                    <div class="bot-btn">
                                        <el-scrollbar style="height:100%;width: 100%;">
                                            <div class="scr-div">
                                                <div class="left-btn">
                                                
                                                </div>
                                                <div class="right-paging">
                                                    <el-pagination @size-change="handleSizeChangejiao" @current-change="handleCurrentChangejiao" background
                                                            :current-page="currentPage" :page-sizes="[100]" :page-size="100"
                                                            :pager-count="5"
                                                            layout="total, sizes, prev, pager, next" :total="total">
                                                    </el-pagination>
                                                </div>
                                            </div>
                                        </el-scrollbar>
                                    </div>
                              </div>

                              
                              <!-- 操作按钮 -->
                             <div class="operate-btn">
                                 <div class="top-btn">
                                       <div class="add-btn  unify-btn" @click="addForwardingVariables">添加 <img src="../assets/btnImg/add.png" ></div>
                                       <div class="del-btn unify-btn" @click="delForwardVariabfn">移除 <img src="../assets/btnImg/del.png" ></div>
                                 </div>
                                 <div class="bottom-btn">
                                    
                                     <div class="moveup-btn unify-btn" @click="variabMoveUp">上移 <img src="../assets/btnImg/moveup.png" ></div>
                                     <div class="down-btn unify-btn" @click="variabMoveDown">下移 <img src="../assets/btnImg/down.png" ></div>
                                 </div>
                             </div>

                              <!-- 移动完的表格 -->
                              <div class="complete table">
                                 <div class="other-type">转发变量</div>
                                     <el-table :data="ForwardVariableTable" height="calc(100% - 85px)" stripe  style="width: 100%;margin-top: 12px;" border 
                                     highlight-current-row @selection-change="handleSelectionChange2" @current-change="handleCurrentChange">
                                         <el-table-column type="index" width="60" align="center"></el-table-column>
                                         
                                         <el-table-column type="selection" width="55" align="center"> </el-table-column>
                                         <el-table-column prop="show_number" width="80" align="center" label="点号"></el-table-column>
                                         <el-table-column prop="variable_name" label="变量名称">
                                              
                                              <template  #default="{row}">
                                               
                                                <div>{{row.fullName != "" ? row.fullName : row.variable_name}}</div>
                                           </template>
                                         </el-table-column>
                                         <el-table-column prop="cofficient" label="系数(修改后保存)" width="120"> 
                                            <template  #default="{row}">
                                                <!-- editCofficient -->
                                                <div @dblclick="editDisplay(row)" v-if="!row.editCofficient">{{row.cofficient}}</div>
                                                <div v-else><el-input v-model="row.cofficient" @blur="saveCelltow(row)"></el-input></div>
                                           </template>
                                         </el-table-column>
                                    </el-table>
                                    <div class="bot-btn">
                                        <el-scrollbar style="height:100%;width: 100%;">
                                            <div class="scr-div">
                                                <div class="left-btn">
                                                
                                                </div>
                                                <div class="right-paging">
                                                    <el-pagination @size-change="handleSizeChangejiao" @current-change="handleCurrentChangejiao2" background
                                                            :current-page="currentPage2" :page-sizes="[100]" :page-size="100"
                                                            :pager-count="5"
                                                            layout="total, sizes, prev, pager, next" :total="total2">
                                                    </el-pagination>
                                                </div>
                                            </div>
                                        </el-scrollbar>
                                    </div>
                              </div>
                              </div>
                        </div>

                <div class="con-bottom" v-if="rowDevItem == '扩展参数' || rowDevItem == '设备信息'">
                    <div class="bottomoperate-btn solidcolor" @click="preservation">保存</div>
                 </div>
                 <div class="con-bottom qitaxinxi" v-if="rowDevItem != '扩展参数' && rowDevItem != '设备信息'">
                    <div class="bottomoperate-btn solidcolor" @click='getAgreementListfn' >转发类型</div>
                    <div class="bottomoperate-btn solidcolor" @click="preservation">保存</div>
                    <div class="bottomoperate-btn bordercolor"  @click="openDaorufnxls">导入</div>
                    <input  type="file" ref="dianfileInput222" accept=".xls,.xlsx"   @change="handleFileUploadxls"  style="display: none">
                    <div class="bottomoperate-btn bordercolor" @click="exportDataExcel">导出</div>
                    <div class="bottomoperate-btn bordercolor teshubtn" @click="templateSpecific">导出模板专用</div>
                 </div>

             
               
            </div>
            <!-- 新增修改转发通道 -->
            <el-dialog width="950px" draggable  :title="caozuoType" :close-on-click-modal='false' v-model="addeditflagline">
                    <div class="leftandrightdialog">
                        <div class="leftdio" style="margin-right:20px">
                          <div class="items">
                                <div class="leftname"><span>*</span> 通道号：</div>
                                <div class="elinputdisabled">{{channelInfo.channel_number}}</div>
                            </div>
                            <div class="items">
                               <div class="leftname"><span>*</span> 通道名称：</div>
                                <el-input v-model="channelInfo.channel_name" placeholder="请输入通道名称"></el-input>
                            </div>
                             
                            <div class="items">
                                <div class="leftname"><span>*</span> 通道类型：</div>
                                <el-select v-model="channelInfo.channel_type" placeholder="请输入通道类型" style="width:100%" :disabled='portType == 7 || portType == 8'> 
                                                <el-option
                                                   v-for="item in thoroughfareOptionType"
                                                   :key="item.value"
                                                   :label="item.label"
                                                   :value="item.value">
                                                   </el-option>
                                 </el-select>
                            </div>
                             <div class="items">
                                <div class="leftname">通道规约：</div>
                                <el-select v-model="channelInfo.channel_protocol" placeholder="请选择通道规约" style="width:100%">
                                                      <el-option
                                                        v-for="item in thoroughfareOptionStatute"
                                                        :key="item.id"
                                                        :label="item.name"
                                                        :value="item.id">
                                                        </el-option>
                                </el-select>
                            </div>
                            <div class="items">
                                 <div class="leftname"><span>*</span> 发送间隔：</div>
                                <el-input v-model="channelInfo.channel_interval" placeholder="请输入发送间隔(ms)"></el-input>
                            </div>
                            <!-- <div class="items">
                                <div class="leftname"><span>*</span> 接受超时：</div>
                                <el-input v-model="channelInfo.timeout" placeholder="请输入接受超时(ms)"></el-input>
                            </div> -->
                        </div>
                        <div class="leftdio">
                           <div class="radio-type">
                            <div class="left-type">
                                  <div class="myname">端口类型：</div>
                                  <div class="myradio">
                                    <!-- <el-radio v-model="portType" label="10">无</el-radio> -->
                                    <el-radio v-model="portType" label="1">串口</el-radio>
                                    <el-radio v-model="portType" label="2">TCP服务端</el-radio>
                                    <el-radio v-model="portType" label="3">TCP客户端</el-radio>
                                    <!-- <el-radio v-model="portType" label="4">MQTT客户端</el-radio>
                                    <el-radio v-model="portType" label="5">UDP客户端</el-radio>
                                    <el-radio v-model="portType" label="6">CAN</el-radio> -->
                                    <el-radio v-model="portType" label="7">DI</el-radio>
                                    <el-radio v-model="portType" label="8">DO</el-radio>
                                  </div>
                            </div>
                            <div class="right-tongdao">
                              <div class="myname">通道设置：</div>
                                <el-checkbox v-model="auto_open"></el-checkbox>
                                <span class="tong">通道自动打开</span>
                            </div>
                           </div>
                           <!-- 串口 -->
                           <div class="body-items" v-if="portType == 1">
                              <div class="items">
                                <div class="leftname"><span>*</span> 串口号：</div>
                                    <el-select v-model="channelInfo.serial_number" filterable allow-create>
                                                <el-option
                                                      v-for="item in serial_numberList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                 </el-select>
                              </div>
                              <div class="items">
                                <div class="leftname"><span>*</span> 奇偶校验：</div>
                               <el-select v-model="channelInfo.parity">
                                                <el-option
                                                      v-for="item in ParityOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              </div>
                              <div class="items">
                               <div class="leftname "><span>*</span> 数据位：</div>
                                 <el-select v-model="channelInfo.data_bits">
                                                <el-option
                                                      v-for="item in dataBitsOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              
                              </div>
                              <div class="items">
                                <div class="leftname"><span>*</span> 波特率：</div>
                                 <el-select v-model="channelInfo.baud_rate">
                                                <el-option
                                                      v-for="item in BAUDOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              </div>
                              <div class="items">
                                  <div class="leftname"><span>*</span> 停止位：</div>
                                  <el-select v-model="channelInfo.stop_bits">
                                                <el-option
                                                      v-for="item in stopBitsOption"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              </div>
                           </div>
                           <!-- TPC服务端 -->
                           <div class="body-items" v-if="portType == 2">
                            <div class="items">
                               <div class="leftname"><span>*</span> 本机地址：</div>
                                <el-input v-model="channelInfo.local_address" placeholder="[IP地址格式]"></el-input>
                                
                            </div>
                             <div class="items">
                               <div class="leftname"><span>*</span> 本机端口：</div>
                                <el-input v-model="channelInfo.local_port" placeholder="[整型数字]"></el-input>
                            </div>
                            <div class="items">
                                <div class="leftname">远方地址：</div>
                                <el-input v-model="channelInfo.remote_address2" placeholder="[IP地址格式]"></el-input>
                            </div>
                           </div>
                           <!-- TPC客户端 -->
                           <div class="body-items" v-if="portType == 3">
                             <div class="items">
                               <div class="leftname "><span>*</span> 远方地址：</div>
                                <el-input v-model="channelInfo.remote_address" placeholder="[IP地址格式]"></el-input>
                            </div>
                             <div class="items">
                                <div class="leftname"><span>*</span> 远方端口：</div>
                                <el-input v-model="channelInfo.remote_port" placeholder="[整型数字]"></el-input>
                            </div>
                           </div>
                           <!-- MQTT客户端 -->
                           <div class="body-items" v-if="portType == 4">
                              <div class="items">
                                <div class="leftname">客户机标识：</div>
                                  <el-input v-model="channelInfo.aaaa" placeholder="请输入客户机标识"></el-input>
                              </div>
                              <div class="items">
                                  <div class="leftname">远程地址：</div>
                                  <el-input v-model="channelInfo.aaaa" placeholder="[IP地址格式]"></el-input>
                              </div>
                              <div class="items">
                                <div class="leftname">发布主题：</div>
                                  <el-input v-model="channelInfo.aaaa" placeholder="请输入发布主题"></el-input>
                                  
                              </div>
                              <div class="items">
                               <div class="leftname ">用户名：</div>
                                <el-input v-model="channelInfo.aaaa" placeholder="请输入用户名"></el-input>
                              </div>
                              <div class="items">
                                  <div class="leftname">远程端口：</div>
                                  <el-input v-model="channelInfo.aaaa" placeholder="[整型数字]"></el-input>
                              </div>
                              <div class="items">
                                <div class="leftname">订阅：</div>
                                  <el-input v-model="channelInfo.aaaa" placeholder="请输入发布主题"></el-input>
                                
                              </div>
                              <div class="items">
                                <div class="leftname ">密码：</div>
                                <el-input v-model="channelInfo.aaaa" placeholder="请输入密码"></el-input>
                            </div>
                           </div>
                           <!-- DI口 -->
                           <div class="body-items" v-if="portType == 7">
                            <div class="items">
                                <div class="leftname"><span>*</span>DI口：</div>
                                <el-input v-model="channelInfo.di_number" placeholder="请输入DI口"></el-input>
                            </div>
                           </div>
                           <!-- DO口 -->
                           <div class="body-items" v-if="portType == 8">
                            <div class="items">
                                <div class="leftname"><span>*</span>DO口：</div>
                                <el-input v-model="channelInfo.do_number" placeholder="请输入DO口"></el-input>
                            </div>
                           </div>
                           
                        </div>
                    </div>
                    <div class="el-loading-mask" v-show="diaisMask">
                            <div class="el-loading-spinner">
                                    <svg viewBox="25 25 50 50" class="circular">
                                        <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                    </svg>
                            </div>
                     </div>
                   <template #footer>
                        <div class="dialog-footer">
                            <el-button  @click="addeditflagline = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="addChannelData" type="primary">确 定</el-button>
                        </div>
                   </template>
            </el-dialog>
         
             <!-- 新增/修改 设备-->
           <el-dialog width="1000px" draggable  :title="nowOperatingDevice" :close-on-click-modal='false' v-model="addDecive">
                    <div class="leftandrightdialog shebeidivdiv">
                        <div class="leftdio" style="margin-right:20px">
                             <div class="items">
                                <div class="leftname"><span>*</span> 设备序号：</div>
                                <div class="elinputdisabled">{{deviceInfo.device_number}}</div>
                               
                             </div>
                              <div class="items">
                                <div class="leftname"><span>*</span> 设备名称：</div>
                               <el-input v-model="deviceInfo.device_name" placeholder="请输入设备名称"></el-input>
                             </div>
                              <div class="items">
                                    <div class="leftname"><span>*</span> 设备地址：</div>
                                    <el-input v-model="deviceInfo.device_address" placeholder="请输入设备地址"></el-input>
                                </div>
                              <div class="items">
                                    <div class="leftname">扩展地址：</div>
                                      <el-input v-model="deviceInfo.device_addressex" placeholder="请输入扩展地址"></el-input>
                                </div>
                                <div class="items">
                                <div class="leftname">设备规约：</div>
                                <el-select v-model="deviceInfo.device_protocol" clearable>
                                                <el-option
                                                v-for="item in thoroughfareOptionStatute"
                                                :key="item.id"
                                                :label="item.name"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                                </div>
                                <div class="items">
                                <div class="leftname">设备投运：</div>
                                <el-checkbox v-model="deviceInfo.run"></el-checkbox>
                            </div>
                             <div class="items">
                               <div class="leftname"> 重新生成变量：</div>
                               <el-checkbox v-model="mychange"></el-checkbox>
                            </div>


                        </div>
                        <div class="leftdio">
                            <div class="items">
                                    <div class="leftname">设备组：</div>
                                     <el-select v-model="deviceInfo.device_group" placeholder="设备组" @change="getDeviceMuban(deviceInfo.device_group,'手动')">
                                                <el-option
                                                v-for="item in deviceGroupList"
                                                :key="item.id"
                                                :label="item.channelName"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                            </div>
                            <div class="items">
                                    <div class="leftname">设备子模板：</div>
                                    <el-select v-model="deviceInfo.device_template" placeholder="设备子模板" @change="getDeviceTempSerialList(deviceInfo.device_template,'手动')">
                                                <el-option
                                                v-for="item in deviceTemList"
                                                :key="item.id"
                                                :label="item.channelName"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                            </div>
                            <div class="items">
                                    <div class="leftname">设备子系列：</div>
                                   <el-select v-model="deviceInfo.device_serial_type" placeholder="设备子系列">
                                                <el-option
                                                v-for="item in deviceSubSeriesList"
                                                :key="item.id"
                                                :label="item.serial_name"
                                                :value="item.id">
                                                </el-option>
                                        </el-select>
                            </div>
                            <div class="items itemright">
                                <div class="leftname"><span>*</span> 中断次数：</div>
                               <el-input v-model="deviceInfo.break_count" placeholder="[1-10数字]"></el-input>
                            </div>
                             <div class="items itemright">
                                <div class="leftname"><span>*</span> 重发次数：</div>
                               <el-input v-model="deviceInfo.resend_count" placeholder="[1-10数字]"></el-input>
                            </div>
                        </div>
                    </div>
                    <div class="el-loading-mask" v-show="diaisMask">
                                    <div class="el-loading-spinner">
                                    <svg viewBox="25 25 50 50" class="circular">
                                        <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                    </svg>
                           </div>
                     </div>
                   <template #footer >
                      <div class="dialog-footer">
                            <el-button  @click="addDecive = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="preservation" type="primary">确 定</el-button>
                      </div>
                    </template>
                      
                    
           </el-dialog>

            <!-- 转发类型弹窗 -->
            <el-dialog width="1000px" draggable  title="转发类型" :close-on-click-modal='false' v-model="drawer">
                <div class="drawer-con">
                        <div class="left-tree">
                             <div class="bottomoperate-btn solidcolor" @click="openAgreement('添加转发协议')">添加转发协议</div>
                             <el-scrollbar style="height:calc(100% - 85px);width: 100%;">
                                    <el-tree class="filter-tree" :data="agreementTree"  
                                        :expand-on-click-node="true" 
                                        default-expand-all
                                        node-key="id" :props="defaultProps2" :highlight-current='true'  ref="tree" 
                                        @node-click="nodeClickzhuanfa"
                                    >
                                    <template #default="{ node }">
                                        <div class="custom-tree-node" >
                                           {{ node.label }}
                                            <div class="treeimg">
                                                <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                                                             <img src="../assets/btnImg/edit2.png" alt="" @click="openAgreement('修改转发协议',node.data)">
                                                        </el-tooltip>
                                                        <el-tooltip class="item" effect="dark" content="删除" placement="top">
                                                             <img src="../assets/btnImg/del2.png" style="margin-left:8px" @click="delAgreement(node.data)">
                                                        </el-tooltip>
                                            </div>
                                        </div>
                                        
                                    </template>
                                    </el-tree>
                                    </el-scrollbar>
                        </div>
                        <div class="right-table">
                             <div class="bottomoperate-btn solidcolor" @click="openAgreementType('添加转发类型')">添加转发类型</div>
                             <el-table :data="TypeTable" max-height="100%" stripe  style="width: 100%;" >
                                        <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
                                        <el-table-column prop="number" width="60" label="编号"> </el-table-column>
                                        <el-table-column prop="name" label="转发类型名称"> </el-table-column>
                                        <el-table-column prop="start_point" label="起始点号(偏移量)" width="120"> </el-table-column>
                                        <el-table-column prop="remark" label="操作" width="160" align="center"> 
                                            <template #default="{row}">
                                                <div class="table-img">
                                                      <img src="../assets/btnImg/edit2.png" alt="" @click="openAgreementType('修改转发类型',row)">
                                                      <img src="../assets/btnImg/del2.png" style="margin-left:20px" @click="delAgreementtype(row)">
                                                </div>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                        </div>
                        <div class="el-loading-mask" v-show="diaisMask">
                            <div class="el-loading-spinner"><svg viewBox="25 25 50 50" class="circular"> <circle cx="50" cy="50" r="20" fill="none" class="path"></circle></svg></div>
                        </div>
                    </div>
                <template #footer>
                        <div class="dialog-footer">
                              
                        </div>
                    </template>
            </el-dialog>

            <!-- 协议类型弹窗 -->
            <el-dialog width="400px" draggable  :title="AgreementType" :close-on-click-modal='false' v-model="dialogflag">
                    <div class="choicedio">
                        <div class="items">
                                <div class="leftname"><span>*</span> 名称：</div>
                                <el-input v-model="agreemenName" placeholder="请输入名称"></el-input>
                            </div>
                            <div class="items">
                                <div class="leftname">备注：</div>
                                <el-input
                                                    type="textarea"
                                                    :rows="2"
                                                    placeholder="请输入内容"
                                                    v-model="agreemenRemarks">
                                                    </el-input>
                            </div>
                    </div>
                    <div class="el-loading-mask" v-show="diaisMask">
                                    <div class="el-loading-spinner">
                                    <svg viewBox="25 25 50 50" class="circular">
                                        <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                    </svg>
                           </div>
                     </div>
                     <template #footer>
                        <div class="dialog-footer">
                              <el-button  @click="dialogflag = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="addAgreement" type="primary">确 定</el-button>
                        </div>
                    </template>
            </el-dialog>
                  
            <!-- 转发类型弹窗 -->
            <el-dialog width="400px" draggable  :title="AgreementType" :close-on-click-modal='false' v-model="zhuandialogflag">
                    <div class="choicedio">
                           <div class="items">
                                    <div class="leftname"><span>*</span> 编号：</div>
                                        <el-input v-model="typeCode" placeholder="请输入编号"></el-input>
                           </div>
                           <div class="items">
                                    <div class="leftname"><span>*</span> 名称：</div>
                                        <el-input v-model="typeName" placeholder="请输入名称"></el-input>
                           </div>
                           <div class="items">
                                    <div class="leftname"><span>*</span> 起始点号：</div>
                                        <el-input v-model="typeQidian" placeholder="请输入起始点号[偏移量]"></el-input>
                           </div>
                            
                    </div>
                    <div class="el-loading-mask" v-show="diaisMask">
                                    <div class="el-loading-spinner">
                                    <svg viewBox="25 25 50 50" class="circular">
                                        <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                    </svg>
                           </div>
                     </div>
                      <template #footer>
                        <div class="dialog-footer">
                             <el-button  @click="zhuandialogflag = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="addAgreementType" type="primary">确 定</el-button>
                        </div>
                    </template>
                   
            </el-dialog>

            <!-- 删除提醒 -->
            <el-dialog width="320px" draggable  title="操作提示" :close-on-click-modal='false'
                    v-model="deldialogflag">
                    <div style="padding: 0px 20px;">
                        <div class="delmydiodiv">
                            <img src="../assets/btnImg/prompt.png" alt=""><span>确定要删除选中项吗？</span>
                        </div>
                    </div>
                    <template #footer>
                        <div class="dialog-footer">
                            <div class="bottomoperate-btn solidcolor">确定</div>
                            <div class="bottomoperate-btn qucolor" @click="deldialogflag = false" style="margin-right:0px">取消</div>
                        </div>
                    </template>
            </el-dialog>
          
          
        </div>
         <div class="el-loading-mask" v-show="isMask">
             <div class="el-loading-spinner"><svg viewBox="25 25 50 50" class="circular"> <circle cx="50" cy="50" r="20" fill="none" class="path"></circle></svg></div>
          </div>
       

    </div>
</template>

<script>
import {deletechannel,findDeviceGroupList,findDeviceTemplate,findDeviceSerial,transmitChannelList,transmitAddChannel,getAgreement,addAgreemntapi,findDeviceGroupListAll,
editAgreementapi,delAgreementapi,forwardingTypeList,addAgreemntapitype,editAgreementapitype,delAgreementapitype,channelconfigEdit,findchannelconfigAll,getChannelAndDeviceState} from "../api/dataComparisonApi.js";
import {infoPtlSo,addDevicechun,editDevicechun,delDevicechun,getiec10xexBind,getiec10xex,addiec10xex,editiec10xex,getModbusexBind,addModbusex,editModbusex,addCdtcanshu,editCdtcanshu
,getModbusex,getCdtcanshuBind,getCdtcanshu,getVariablesDevice,getDeviceList,getvAllAriablesList,saveForward} from "../api/Interface.js";
import {findForwardVariableList,saveForwardVariableList,delForwardVariableList,getChannelconfigidleNumber,getDeviceconfigidleNumber} from "../api/forwardApi.js";
import * as XLSX from "xlsx";  
import * as FileSaver from "file-saver";  
export default {
    data() {
        return {
        allVariables:[],//全部变量
        currentRow:{},
        addeditflagline:false,//添加通道弹窗
        caozuoType:"添加通道",
        panduan:false,
        leftLevel:11000,
        radio:"1",
        aaaa:"",
        auto_open:true,//通道自动打开
        isMask:false,
        diaisMask:false,
        rowDevItem:"设备信息",
        deviceItem:['设备信息'], //设备的可选项
        deviceItemArr:[],
        nowdeviceItemObj:{},
        deviceList:[],//设备列表数据
        nodeFlag:false,//树节点操作弹窗
        addDecive:false,//设备弹窗
        mylevel:1,
        mymouseX:160,
        mymouseY:6,
        options: [],
        value: '',
        checked:true,
        dataList:[
            {
                'channelName':"转发通道",
                'channels':[],
                'level':11000
            }
        ],
        defaultProps: {
              children: 'channels',
              label: 'channelName',
        },
        isDdevice:false,//判断通道还是设备
        mychange:false,
        deviceInfo:{
                device_name:"",
                device_addressex:"",
                device_address:"",
                device_number:"",
                device_protocol:"",
                device_group:"",
                device_template:"",
                device_serial_type:"",
                break_count:"",
                resend_count:"",
                run:true,
                mqtt:false,
                change:false,

        },//设备信息
        deviceGroupList:[],//设备组
        versionList:[
            {
                'channelName':"02版",
                "id":1,
            },
            {
                'channelName':"其他",
                "id":2,
            }
        ],//版本
        deviceTemList:[
            {
                             'channelName':"无",
                             'id':'0',
                             'device_group_id':0,
                             'type':"设备模板",
                }
        ],//设备组模板
        deviceSubSeriesList:[
            {
                             'serial_name':"无",
                             'id':'0',
                             'device_group_id':0,
                             'type':"设备子系列",
                }
        ],//设备子系列
        nowOperatingDevice:"添加设备",//判断是添加设备还是修改设备
        thoroughfareInfo:{},//扩展参数
        regionList:[
            {
                'name':"默认区域",
                'id':0
            }
        ],//所属区域
        //当前选中的协议
        nowagreementObj:{},
        //新通道信息
        channelInfo:{
           //TCP服务端
            local_port:"",
            local_address:"",
            remote_address2:"",
            //TCP客户端
            remote_address:"",
            remote_port:"",
            auto_open:true,//通道自动打开
            serial_number:"1", //串口号
            parity:"1", //奇偶校验
            stop_bits:"", //停止位
            baud_rate:"", //波特率
            data_bits:"", //数据位
            "channel_name": "",
            "channel_number": "",
            "channel_type": "",
            "channel_protocol": "",
            "channel_interval": "",
            "port_type": "",
            "device_count": "",
            di_number:"",
            do_number:""
        },
        //通道类型
        thoroughfareOptionType:[
          {
          value: 0,
          label: '全双工协议通道'
        },
          {
          value: 1,
          label: '问答式协议通道'
        },
        ],
        //通道规约
        thoroughfareOptionStatute:[],
        //通道端口类型
        portType:"1",
        thoroughfareOptionPort:[
             {
            value: '0',
            label: '无'
            },{
            value: '1',
            label: '串口'
            },
             {
            value: '2',
            label: 'Tcp服务端'
            },
             {
            value: '3',
            label: 'Tcp客户端'
            },
             {
            value: '4',
            label: 'MQTT客户端'
            },
        ],
        serial_numberList:[
          {
            'label':"1",
            'value':"1",
          },{
            'label':"2",
            'value':"2",
          },
        ],
        //波特率
        BAUDOption:[
            {
            value: '100',
            label: '100'
            },{
            value: '300',
            label: '300'
            },
             {
            value: '600',
            label: '600'
            },
             {
            value: '1200',
            label: '1200'
            },
             {
            value: '2400',
            label: '2400'
            },
             {
            value: '4800',
            label: '4800'
            },
             {
            value: '9600',
            label: '9600'
            },
             {
            value: '14400',
            label: '14400'
            },
             {
            value: '19200',
            label: '19200'
            },
             {
            value: '38400',
            label: '38400'
            },
             {
            value: '56000',
            label: '56000'
            },
             {
            value: '57600',
            label: '57600'
            },
             {
            value: '115200',
            label: '115200'
            },
             {
            value: '128000',
            label: '128000'
            },
             {
            value: '256000',
            label: '256000'
            },
        ],
        //奇偶校验
        ParityOption:[
            {
            value: '0',
            label: '无校验'
            },
            {
            value: '1',
            label: '奇校验'
            },
             {
            value: '2',
            label: '偶校验'
            }
        ],
        //数据位
        dataBitsOption:[
            {
            value: '8',
            label: '8'
            },{
            value: '7',
            label: '7'
            }
        ],
        //停止位
        stopBitsOption:[
              {
            value: '0',
            label: '1'
            },{
            value: '1',
            label: '2'
            }
        ],
        
        yuanshi:{},
        leftTable:[],//转发类型表格数据
        TypeTable:[],//转发类型表格数据
        drawer: false,//转发类型抽屉
        agreementTree:[
            {
                'name':"转发通道",
                id:"000001111",
                children:[]
            }
        ],//转发协议树形数据
        defaultProps2: {
              children: 'children',
              label: 'name',
        },
        dialogflag:false,//协议类型新增编辑弹窗
        typeCode:"",//转发类型弹窗参数
        typeName:"",//转发类型弹窗参数
        typeQidian:"",//转发类型弹窗参数
        agreemenName:"",//协议类型弹窗参数
        agreemenRemarks:"",//协议类型弹窗参数
        zhuandialogflag:false,//转发类型新增编辑弹窗
        deldialogflag:false,//删除弹窗
        AgreementType:"添加转发协议",//判断添加/修改转发协议
        AgreementRow:{},//当前需要修改的协议
        AgreementRowZhuanfa:{},//协议类型
        //101扩展参数
        ExtendedParameters101:{

        },
        //104扩展参数
        ExtendedParameters104:{

        },
        //Modbus子站参数扩展参数
        ExtendedParametersModbus:{

        },
        //CDT扩展参数
        ExtendedParametersCDT:{

        },
        nowAddOrEditCanshu:"添加参数",//判断是添加参数还是修改参数
        transfer_id:1,
        nowOperatingChannel:'添加通道',

        nowLeftRow:{},//左边树形结构
        channelList:[],//转发通道列表
        noeFlag:false,

         //转发变量参数
         deviceArr:[],
         gatherDataList:[
             {
                'treeName':"采集通道",
                'children':[],
                'mytype':"channel",
                'myid':1000000000001
            },
             {
                'treeName':"状态量",
                'children':[
                    {
                        'treeName':"channelstate",
                        'children':[],
                        'mytype':"device",
                        'myid':1000000000003
                    },
                    {
                        'treeName':"devicestate",
                        'children':[],
                        'mytype':"device",
                        'myid':1000000000004
                    },
                ],
                'mytype':"channel",
                'myid':1000000000002
            },
         ],
         channelstateList:[],
         devicestateList:[],
         collectDefaultProps: {
                children: 'children',
                label: 'treeName',
         },
         nowcollecDeviceItem:{},
         collecVariablTable:[],//采集变量表格数据
         collecVariablTableCopy:[],//采集变量表格数据
         collecVariabData:[],//当前选中的采集变量
         ForwardVariableTable:[],//转发变量表格数据
         ForwardVariableTableCopy:[],//转发变量表格数据
         forwardVariabData:[],
         gudingDevice_number:"",//设备号
         gudingChannel_number:"",//通道号
         deviceGroundAll:[],//设备组
         deviceMunbanAll:[],//设备模板
         deviceSonAll:[],//设备子系列
         currentPage:1,
         currentPage2:1,
         total:0,
         total2:0,
        };
   
        
    },
    watch:{
        // portType(val){
        // if(val == 7 || val == 8){
        //     this.channelInfo.channel_type = 2
        // }else {
        //     this.channelInfo.channel_type = 0
        // }
        // },
    },

    mounted() {
        this.getVariablesAll()
        this.getALLDeviceMuban()
        this.getDeviceconfigidleNumberfn()
        this.getChannelconfigidleNumberfn()
        //获取转发通道列表
        this.getList()
        //查询规约
        this.getinfoPtlSo()
        //查看设备组
        this.getDeviceGroupApi()
        this.getAgreementList()
        this.getDeviceListData()
    },

    methods: {
        //双击修改系数
        editDisplay(row){
            row.editCofficient = true
        },
        //系数失去焦点
        saveCelltow(row){
            if(row.cofficient === ""){
                this.$message({showClose: true,message: '系数不能为空',type: 'warning'});
                return
            }
            row.editCofficient = false
        },
        //查询全部变量
        getVariablesAll(){
            getvAllAriablesList().then(res => {
                // console.log("全部采集变量",res);
                 if(res != undefined){
                    this.allVariables = res
                 }
            })
        },
        //查询空闲的设备号
        getDeviceconfigidleNumberfn(){
            getDeviceconfigidleNumber().then(res => { 
                if(res != undefined){
                    this.gudingDevice_number = res.idle
                }
            })
        },
        //查询空闲的通道号
        getChannelconfigidleNumberfn(){
            getChannelconfigidleNumber().then(res => { 
                if(res != undefined){
                this.gudingChannel_number = res.idle
                }
            })
        },
        //查询规约
        getinfoPtlSo(){
            infoPtlSo().then(res => {
                  var wuArr = [{
                      "hide": 1,
                      "id": 0,
                      "name": "无规约",
                      "protocol_name": "无规约",
                      "status": 1,
                      "protocol_alias":"",
                      "suffix": ".so"
                  }]
                  if(res != undefined){
                      this.thoroughfareOptionStatute = wuArr.concat(res)
                  }
            })
        },
         //获取设备模板组
        getDeviceGroupApi(){
            this.isMask = true
             this.deviceGroupList = [
                {
                    'channelName':'无',
                    'id':'0',
                    'type':"模板组",
                }
            ]
             findDeviceGroupList().then(res => {
                if(res){
                    res.forEach(item => {
                          this.deviceGroupList.push({
                             'channelName':item.device_group_name,
                             'id':item.id,
                             'type':"模板组",
                          })
                    })
                    // console.log(this.deviceGroupList);
                }
                this.isMask = false
            }).catch(() => {
                     this.isMask = false
              })
        },
        //获取设备模板
        getDeviceMuban(row,type){
            if(row === "" || row === "0"){
                this.deviceTemList = [{
                             'channelName':"无",
                             'id':"0",
                             'device_group_id':0,
                             'type':"设备模板",
                }]
                this.deviceInfo.device_template = "0"
                this.deviceSubSeriesList = [
                    {
                      'serial_name':"无",
                      'id':'0',
                      'device_group_id':0,
                      'type':"设备子系列",
                    }
                ]
                this.deviceInfo.device_serial_type = "0"
               return
            }
            this.diaisMask = true
             findDeviceTemplate(row).then(res => {
                   if(res){
                    var arr = []
                    res.forEach(item => {
                          arr.push({
                             'channelName':item.device_template_name,
                             'id':item.id,
                             'device_group_id':item.device_group_id,
                             'type':"设备模板",
                          })
                    })
                    this.deviceTemList = arr
                    if(type == '手动' && this.deviceTemList.length != 0){
                          this.deviceInfo.device_template = this.deviceTemList[0].id
                          this.getDeviceTempSerialList(this.deviceTemList[0].id,'手动')
                    }
                }
                   this.diaisMask = false
             }).catch(() => {
                     this.diaisMask = false
              })
        },
        //查询设备模板的子系列
        getDeviceTempSerialList(row,type){
            // var d = {
            //       "device_template_id":row
            // }
            if(row === "" || row === 0){
                return
            }
            this.diaisMask = true
            findDeviceSerial(row).then(res => {
                  this.diaisMask = false

                 if(res){
                     this.deviceSubSeriesList = res
                     if(type =='手动' && res.length != 0){
                          this.deviceInfo.device_serial_type = res[0].id
                     }
                 }
            }).catch(() => {
                     this.diaisMask = false
              })
        },
        //获取转发通道列表
        getList(){
            this.isMask = true
           transmitChannelList().then(res => {
            // console.log("获取转发通道列表",res);
              this.isMask = false
              var myid = 1
            //   return
              //扩展参数根据extend_type来判断,大于0才有扩展参数，设备信息都有
              //所属区域先定死个默认区域传0，设备组就是设备模板的模板组，设备子模板就是设备模板，设备子系列也在设备模板页面
              //设备规约就是通道规约，然后不选的话，就沿用通道的规约
              var devExtendType = ""
              var agreementId = ""
              var channelArr = []
              
               var recursiveFunction=function() {
                const getStr=function(list) {
                    list.forEach(function(row) {
                    if(row.channels && row.channels.length != 0) {
                        // console.log("有通道的协议",row);
                        devExtendType = row.extend_type
                        agreementId = row.id
                        row.channelName = row.name
                        row.mytype = 'channel'
                        row.level = 1
                        row.myid = myid++
                        getStr(row.channels)
                    } else {
                        if(row.hasOwnProperty('extend_type')) {
                        //    console.log("无通道的协议",row);
                           devExtendType = row.extend_type
                           row.channelName = row.name
                           row.mytype = 'channel'
                           row.myid = myid++
                           row.level = 1
                       }else {
                          if(row.hasOwnProperty('devices')){
                                // console.log("协议下的通道",row);
                                row.channels = row.devices
                                row.channelName = row.channel_name
                                row.mytype = 'channel'
                                row.level = 2
                                row.myid = myid++
                                channelArr.push(row)
                                getStr(row.devices)
                            }else {
                                //  console.log("通道下的设备",row)
                                 row.channelName = row.device_name
                                 row.level = 3
                                 row.devAgreementId = agreementId
                                 row.devType = devExtendType
                                 row.mytype = 'device'
                                 row.myid = myid++
                            }
                       } 
                    }
                    })
                }
                getStr(res)
                }
                recursiveFunction()
                this.dataList[0].channels = res
                // console.log("res",res);
                this.channelList = channelArr
                // console.log("转发通道列表",channelArr);
                if(res.length != 0){
                    //判断第一次加载
                    if(this.noeFlag){
                        // console.log("触发",this.nowLeftRow);
                          this.leftLevel = this.nowLeftRow.level
                          this.$nextTick(() => {
                            this.$refs.tree.setCurrentNode(this.nowLeftRow);
                            var rows = this.$refs.tree.getCurrentNode()
                             this.leftnodeClick(rows)
                        })
                    }else {
                        this.leftLevel = res[0].level
                        this.$nextTick(() => {
                            this.leftnodeClick(res[0])
                            this.$refs.tree.setCurrentNode(res[0]);
                        })
                    }
                    
                }
           }).catch(() => {
              this.isMask = false
           })
        },
        //通道下设备列表
        handleDeviceDataFn(row){
        // console.log("通道下设备列表",row);
           var ResData = row
           var arr1 = []
           var arr2 = []
           var arr3 = []
           var arr4 = []

              row.forEach(item => {
               item.run = item.run == 1 ? true : false
               item.change = false
              item.mqtt = false
              arr1 =  this.thoroughfareOptionStatute.filter(tt => tt.id == item.device_protocol)
              if(arr1.length != 0){
                  item.device_protocol_name = arr1[0].name
              }else {
                 item.device_protocol_name = ""
              }
              //设备组
              arr2 =  this.deviceGroundAll.filter(tt => tt.id == item.device_group)
              item.device_group_name = arr2.length != 0 ? arr2[0].device_group_name : ""
              //设备模板
              arr3 =  this.deviceMunbanAll.filter(tt => tt.id == item.device_template)
              item.device_template_name = arr3.length != 0 ? arr3[0].device_template_name : ""
              //设备子系列
              arr4 =  this.deviceSonAll.filter(tt => tt.id == item.device_serial_type)
              item.device_serial_type_name = arr4.length != 0 ? arr4[0].serial_name : ""
            })
            this.deviceList = ResData
            // console.log("this.deviceList",this.deviceList);
        },
      
        //左边树形结构点击
        leftnodeClick(row){
            // console.log("点击",row);
            this.leftLevel = row.level
            this.nowLeftRow = row
            if(row.level == 1){//协议
               this.nodeClickzhuanfa(row)
               this.transfer_id = row.id
                // this.thoroughfareInfo = {
                //     MainPort:{}
                // }
                // this.isDdevice = false
            }else if(row.level == 2){ //通道
               this.channelInfo = row
            //    console.log("this.channelInfo",this.channelInfo);
               this.transfer_id = row.transfer_id
               this.portType = row.port_type
            //    this.isDdevice = false
               //处理通道下设备列表
               this.handleDeviceDataFn(row.channels)
            //    this.deviceList = row.channels
            }else if(row.level == 3){ //设备
               this.deviceInfo = row
            //    console.log("设备",row);
            //    this.isDdevice = true
               this.rowDevItem = '设备信息'
               this.nowOperatingDevice = '修改设备'
               this.deviceItem = ['设备信息']
               if(row.devType > 0){
                   this.deviceItem = ['设备信息','扩展参数']
               }
               
               this.isMask = true
               this.deviceItemArr = []
               forwardingTypeList(row.devAgreementId).then(res => {
                if(res != undefined){
                    res.forEach(item => {
                         this.deviceItem.push(item.name)
                         this.deviceItemArr.push(item)
                    })
                }
                    this.isMask = false
                }).catch(() => {
                this.isMask = false
                })
                
              this.deviceInfo.device_protocol = row.device_protocol
              // console.log("规约",this.thoroughfareOptionStatute);
              //根据设备ID来获取扩展参数
              this.getExtendedParameters(row.device_id,row.devType)

               this.deviceInfo.run = row.run == 1 ? true :false
               this.deviceInfo.change = false
               this.deviceInfo.mqtt = false
               if(row.device_group == 0){
                row.device_group = String(row.device_group)
               }else {
                 this.getDeviceTempSerialList(row.device_template)
               }
               this.getDeviceMuban(row.device_group)

            }
            
        },
        //根据设备ID来获取扩展参数
        getExtendedParameters(id,type){
  
            if(type == 1){//101 需要根据 iec_type 字段区分 101 104 协议类型
                //判断是否有绑定，如果有，就获取参数，然后走修改接口。如果没有，就直接走添加参数接口，不用获取
                getiec10xexBind(id).then(res => {
                 
                    if(res.bind){
                         this.nowAddOrEditCanshu = '修改参数'
                         getiec10xex(id).then(res => {
                      
                            this.ExtendedParameters101 = res
                            this.ExtendedParameters101.balance =  this.ExtendedParameters101.balance == 1 ? true : false
                            this.ExtendedParameters101.yc_tran_type =  String(res.yc_tran_type)
                            this.ExtendedParameters101.yx_tran_type =  String(res.yx_tran_type)
                            
                        })
                    }else {
                         this.nowAddOrEditCanshu = '添加参数'
                    }
                })
                
            }else if(type  == 2){//104 需要根据 iec_type 字段区分 101 104 协议类型
                getiec10xexBind(id).then(res => {
               
                    if(res.bind){
                         this.nowAddOrEditCanshu = '修改参数'
                         getiec10xex(id).then(res => {
              
                            this.ExtendedParameters104 = res
                        })
                    }else {
                         this.nowAddOrEditCanshu = '添加参数'
                    }
                })
            }else if(type == 3){//modbus
                getModbusexBind(id).then(res => {
            
                    if(res.bind){
                         this.nowAddOrEditCanshu = '修改参数'
                         getModbusex(id).then(res => {
                          
                            this.ExtendedParametersModbus = res
                        })
                    }else {
                         this.nowAddOrEditCanshu = '添加参数'
                    }
                })
                

            }else {//CDT
                getCdtcanshuBind(id).then(res => {
              
                    if(res.bind){
                         this.nowAddOrEditCanshu = '修改参数'
                         getCdtcanshu(id).then(res => {
                        
                            this.ExtendedParametersCDT = res
                        })
                    }else {
                         this.nowAddOrEditCanshu = '添加参数'
                    }
                })
            }
            
        },
        //树形结构右键点击事件
        onRightClick(event,row){
             event.preventDefault(); // 阻止默认右键菜单

            // 获取鼠标点击位置的坐标
            const mouseX = event.clientX;
            const mouseY = event.clientY;
            this.mymouseX = mouseX - 168
            this.mymouseY = mouseY - 68
            this.nodeFlag = true
            this.nowagreementObj = row

            this.mylevel = row.level
            if(row.level == 2){
                 this.nowOperatingChannel = '添加通道'
            }
            // console.log("this.mymouseX",row);

            // 在这里可以执行你想要的操作，例如显示自定义右键菜单等
            

        },
        //添加通道
        addChannel(){
            // console.log("window.location.host",window.location.host);
            var url = window.location.host.split(':');//页面路径
            // this.thoroughfareInfo = {}
            // this.isDdevice = false
            // console.log("this.thoroughfareOptionStatute",this.thoroughfareOptionStatute);
            var ids = ""
            if(this.thoroughfareOptionStatute.length != 0){
                ids = this.thoroughfareOptionStatute[0].id
            }
            var arr1 = this.thoroughfareOptionStatute.filter(item => item.name == 'txjprotocol104_cong')
            if(arr1.length != 0){
                ids = arr1[0].id
            }

            this.channelInfo = {
           //TCP服务端
            local_port:url[1] ? url[1] : '80',
            local_address:url[0],
            //TCP客户端
            remote_address:"",
            remote_port:"",
            auto_open:true,//通道自动打开
            serial_number:"1", //串口号
            parity:"0", //奇偶校验
            stop_bits:"1", //停止位
            baud_rate:"9600", //波特率
            data_bits:"8", //数据位
            "channel_name": "",
            "channel_number": this.gudingChannel_number,
            "channel_type": 1,
            "channel_protocol": 0,
            "channel_interval": "100",
            "port_type": "",
            "device_count": "",
            'remote_address2':"",
            di_number:"",
            do_number:""
        }
        this.portType = "2"
        this.caozuoType = '添加通道'
            this.addeditflagline = true
        },
        //修改通道
        editChannel(){
            // console.log("表格",val);
            this.channelInfo.auto_open = (this.channelInfo.auto_open.auto_open == 1 ? true : false)
            this.portType = String(this.channelInfo.port_type)
            this.caozuoType = `编辑通道 (${this.channelInfo.channel_name})`
            this.channelInfo.remote_address2 = this.channelInfo.remote_address
            this.channelInfo.parity = JSON.stringify(this.channelInfo.parity)
            // this.channelInfo.remote_address2 = 123
            this.addeditflagline = true
        },
      
        //确定添加转发通道
        addChannelData(){
            // "transfer_id": this.transfer_id,
                 //  "is_transfer": 1, //代表是转发通道
                    // "transfer_id": 1,//代表是转发协议ID
         if(this.channelInfo.channel_name === ""){
            this.$message({showClose: true,message: '通道名称不能为空',type: 'warning'});
            return
        }
        if(this.channelInfo.channel_number === ""){
            this.$message({showClose: true,message: '通道号不能为空',type: 'warning'});
            return
        }
        if(this.channelInfo.channel_type === ""){
            this.$message({showClose: true,message: '请选择通道类型',type: 'warning'});
            return
        }
        if(this.channelInfo.channel_interval === ""){
            this.$message({showClose: true,message: '发送间隔不能为空',type: 'warning'});
            return
        }
        if(this.channelInfo.channel_protocol === ""){
              this.$message({showClose: true,message: '通道规约不能为空',type: 'warning'});
        }
       
              var dd = {}
               
                //串口portType
            if(this.portType == 1){
                if(this.channelInfo.serial_number === ""){
                this.$message({showClose: true,message: '串口号不能为空',type: 'warning'});
                return
                }
                if(this.channelInfo.baud_rate === ""){
                    this.$message({showClose: true,message: '波特率不能为空',type: 'warning'});
                    return
                }
                if(this.channelInfo.parity === ""){
                    this.$message({showClose: true,message: '校验位不能为空',type: 'warning'});
                    return
                }
                if(this.channelInfo.data_bits === ""){
                    this.$message({showClose: true,message: '数据位不能为空',type: 'warning'});
                    return
                }
                if(this.channelInfo.stop_bits === ""){
                    this.$message({showClose: true,message: '停止位不能为空',type: 'warning'});
                    return
                }
                dd = {
                    "channel_name": this.channelInfo.channel_name,
                    "channel_number": Number(this.channelInfo.channel_number),
                    "channel_type": Number(this.channelInfo.channel_type),
                    "channel_protocol": this.channelInfo.channel_protocol,
                    "channel_interval": Number(this.channelInfo.channel_interval),
                    "port_type": 1,
                    "auto_open": this.auto_open ? 1 : 2,
                    "device_count": 10,
                    "serial_number": Number(this.channelInfo.serial_number),
                    "baud_rate": Number(this.channelInfo.baud_rate),
                    "parity":  Number(this.channelInfo.parity),
                    "data_bits": Number(this.channelInfo.data_bits),
                    "stop_bits": Number(this.channelInfo.stop_bits),
                    "is_transfer": 1,
                    "transfer_id": this.transfer_id,
                    }
            }else if(this.portType == 2){ //TCP服务端
                  if(this.channelInfo.local_port === ""){
                    this.$message({showClose: true,message: '本机端口不能为空',type: 'warning'});
                    return
                }
                if(this.channelInfo.local_address === ""){
                    this.$message({showClose: true,message: '本机地址不能为空',type: 'warning'});
                    return
                }
                dd = {
                    "channel_name": this.channelInfo.channel_name,
                    "channel_number": Number(this.channelInfo.channel_number),
                    "channel_type": Number(this.channelInfo.channel_type),
                    "channel_protocol": this.channelInfo.channel_protocol,
                    "channel_interval": Number(this.channelInfo.channel_interval),
                    "port_type": 2,
                    "remote_address":this.channelInfo.remote_address2,
                    "auto_open": this.auto_open ? 1 : 2,
                    "device_count": 10,
                    "local_port": Number(this.channelInfo.local_port),
                    "local_address": this.channelInfo.local_address,
                    "is_transfer": 1,
                    "transfer_id": this.transfer_id,
                    }

            }else if(this.portType == 3){ //TCP客户端
                if(this.channelInfo.remote_port === ""){
                this.$message({showClose: true,message: '远方端口不能为空',type: 'warning'});
                    return
                }
                if(this.channelInfo.remote_address === ""){
                this.$message({showClose: true,message: '远方地址不能为空',type: 'warning'});
                    return
                }
                dd = {
                    "channel_name": this.channelInfo.channel_name,
                    "channel_number": Number(this.channelInfo.channel_number),
                    "channel_type": Number(this.channelInfo.channel_type),
                    "channel_protocol": this.channelInfo.channel_protocol,
                    "channel_interval": Number(this.channelInfo.channel_interval),
                    "port_type": 3,
                    "auto_open": this.auto_open ? 1 : 2,
                    "device_count": 10,
                    "remote_port": Number(this.channelInfo.remote_port),
                    "remote_address": this.channelInfo.remote_address,
                    "is_transfer": 1,
                    "transfer_id": this.transfer_id,
                    }
            }else if(this.portType == 7){
                if(this.channelInfo.di_number === ""){
                    this.$message({showClose: true,message: 'DI口不能为空',type: 'warning'});
                        return
                    }
                dd = {
                    "channel_name": this.channelInfo.channel_name,
                    "channel_number": Number(this.channelInfo.channel_number),
                    "channel_type": Number(this.channelInfo.channel_type),
                    "channel_protocol": this.channelInfo.channel_protocol,
                    "channel_interval": Number(this.channelInfo.channel_interval),
                    "port_type": 7,
                    "auto_open": this.auto_open ? 1 : 2,
                    "device_count": 10,
                    "di_number": Number(this.channelInfo.di_number),
                    "is_transfer": 1,
                    "transfer_id": this.transfer_id,
                    }
            }else if(this.portType == 8){
                if(this.channelInfo.do_number === ""){
                    this.$message({showClose: true,message: 'DO口不能为空',type: 'warning'});
                        return
                    }
                dd = {
                    "channel_name": this.channelInfo.channel_name,
                    "channel_number": Number(this.channelInfo.channel_number),
                    "channel_type": Number(this.channelInfo.channel_type),
                    "channel_protocol": this.channelInfo.channel_protocol,
                    "channel_interval": Number(this.channelInfo.channel_interval),
                    "port_type": 8,
                    "auto_open": this.auto_open ? 1 : 2,
                    "device_count": 10,
                    "do_number": Number(this.channelInfo.do_number),
                    "is_transfer": 1,
                    "transfer_id": this.transfer_id,
                }
                
            }else if(this.portType == 10){
                dd = {
                    "channel_name": this.channelInfo.channel_name,
                    "channel_number": Number(this.channelInfo.channel_number),
                    "channel_type": Number(this.channelInfo.channel_type),
                    "channel_protocol": this.channelInfo.channel_protocol,
                    "channel_interval": Number(this.channelInfo.channel_interval),
                    "port_type": 10,
                    "auto_open": this.auto_open ? 1 : 2,
                    "device_count": 10,
                    "is_transfer": 1,
                    "transfer_id": this.transfer_id,
                }
            }
                
                    //  return
            if(this.caozuoType == '添加通道'){
                // var findIndexNum = this.channelList.filter(item => item.channel_number == this.channelInfo.channel_number)
                // if(findIndexNum.length != 0){
                //         this.$message({showClose: true,message: '此通道号已存在！',type: 'warning'});
                //         return
                // }
                if(this.portType == 1){
                    var findIndexNum = this.channelList.filter(item => item.serial_number == this.channelInfo.serial_number)
                    if(findIndexNum.length != 0){
                        this.$message({showClose: true,message: '此串口号已存在！',type: 'warning'});
                        return
                    }
                }
                  this.diaisMask = true
                    transmitAddChannel(dd).then(res => {
                        this.diaisMask = false
                        if(res.code == 200){
                               this.getChannelconfigidleNumberfn()
                                this.$message({showClose: true,message: '新增成功',type: 'success'});
                                this.addeditflagline = false
                                this.noeFlag = true
                                this.getList()
                            }else {
                                this.$message({showClose: true,message: '新增失败，'+res.msg,type: 'error'});
                            }
                    }).catch(() => {
                    this.diaisMask = false
                    })
             }else {
                 console.log("修改",this.channelInfo);
                 dd.channel_id = this.channelInfo.channel_id
                  this.diaisMask = true
                  channelconfigEdit(dd).then(res => {
                        this.diaisMask = false
                        // console.log("更新通道",res);
                        if(res.code == 200){
                            this.$message({showClose: true,message: '修改成功',type: 'success'});
                            this.noeFlag = true
                            this.getList()
                            this.addeditflagline = false
                        }else {
                            this.$message({showClose: true,message: '修改失败',type: 'error'});
                        }
                    })
             }
        },
        //添加设备旧
        addDevices(){
           this.deviceInfo = {
                device_name:"",
                device_addressex:"",
                device_address:"",
                device_number:this.gudingDevice_number,
                device_protocol:"",
                device_group:"",
                device_template:"",
                device_serial_type:"",
                break_count:"",
                resend_count:"",
                run:true,
                mqtt:false,
                change:false
             }
           this.nowOperatingDevice = '添加设备'
            this.deviceItem = ['设备信息'] //设备的可选项
        //    this.isDdevice = true
        },
        
         //新增设备
        addDecivefn(){
            // this.channelInfo
             this.mychange = false
             this.nowOperatingDevice = "添加设备"
             this.deviceInfo = {
                protocolType:0,
                device_name:"",
                device_addressex:"0",
                device_address:"0",
                device_number:this.gudingDevice_number,
                device_protocol:this.channelInfo.channel_protocol,
                device_group:"0",
                device_template:"0",
                device_serial_type:"0",
                break_count:"3",
                resend_count:"1",
                run:true,
                mqtt:false,
                change:false
             }
              this.deviceTemList = [
                {
                             'channelName':"无",
                             'id':'0',
                             'device_group_id':0,
                             'type':"设备模板",
                }
            ]
            this.deviceSubSeriesList = [
                {
                             'serial_name':"无",
                             'id':'0',
                             'device_group_id':0,
                             'type':"设备子系列",
                }
            ]
             this.rowDevItem = '设备信息'
             this.addDecive = true
        },
        //获取全部设备模板、子系列
        getALLDeviceMuban(){
            findDeviceGroupListAll().then(res => {
                this.isMask = false
                if(res != undefined){
                     var RESDATA = res
                      var arr1 = [
                        {
                            'device_group_name':'无',
                            'id':'0',
                            'type':"模板组",
                        }
                     ]
                     var arr2 = [
                        {
                             'device_template_name':"无",
                             'id':'0',
                             'device_group_id':0,
                             'type':"设备模板",
                }
                     ]
                     var arr3 = [
                        {
                             'serial_name':"无",
                             'id':'0',
                             'device_group_id':0,
                             'type':"设备子系列",
                }
                     ]
                     RESDATA.forEach(item => {
                         //第一层为模板组
                         arr1.push(item)
                         //第二层为设备模板
                         item.children.forEach(towitem => {
                            arr2.push(towitem)
                            //第三层为设备子系列
                            towitem.children.forEach(threeitem => {
                                 arr3.push(threeitem)
                            })
                         })
                     })
                     this.deviceGroundAll = arr1
                     this.deviceMunbanAll = arr2
                     this.deviceSonAll = arr3
                }
            }).catch(() => {
                this.isMask = false
            })
        },
        
        //修改设备
        editDevice(row){
            // console.log("修改设备",row);
             if(row.device_group === 0){
                 row.device_group =String(row.device_group)
             row.device_template =String(row.device_template)
             row.device_serial_type =String(row.device_serial_type)

             }


             this.nowOperatingDevice = `修改设备(${row.device_name})`
             this.deviceInfo = row
             this.mychange = false
             this.getDeviceMuban(row.device_group,"自动")
             this.getDeviceTempSerialList(row.device_template,"自动")
             this.addDecive = true
        },
        //删除通道
        delChannel(){
            if(this.deviceList.length != 0){
                this.$message({showClose: true,message: '当前通道下有设备，不可删除有设备的通道！',type: 'warning'});
                return
            }
            this.$confirm(`是否要删除此通道？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
               deletechannel({'channel_number':this.channelInfo.channel_number}).then(res => {
                  if(res.code == 200){
                    
                      this.getChannelconfigidleNumberfn()
                     this.$message({showClose: true,message: '删除成功',type: 'success'});
                     this.getList()
                     this.leftLevel = 11000
                  }else {
                     this.$message.error('删除失败！！')
                  }
               }).catch(error => {
               })     
            }).catch(() => {
              // ...
            });
        },
        //删除设备
        delDevices(row){
             this.$confirm(`是否要删除此设备？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
               delDevicechun(row.device_id).then(res => {
                  if(res.code == 200){
                    this.getDeviceconfigidleNumberfn()
                     this.$message({showClose: true,message: '删除成功',type: 'success'});
                     this.noeFlag = true
                     this.getList()
                  }else {
                      this.$message.error('删除失败！！')
                  }
               }).catch(error => {
                    this.$message.error('删除失败！！')
               })     
            }).catch(() => {
              // ...
            });
        },
        //删除设备
        delDevices2(){
             this.$confirm(`是否要删除此设备？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
               delDevicechun(this.nowagreementObj.device_id).then(res => {
                  if(res.code == 200){
                    this.getDeviceconfigidleNumberfn()
                     this.$message({showClose: true,message: '删除成功',type: 'success'});
                     this.noeFlag = true
                     this.getList()
                  }else {
                      this.$message.error('删除失败！！')
                  }
               }).catch(error => {
                    this.$message.error('删除失败！！')
               })     
            }).catch(() => {
              // ...
            });
        },
        
        //保存设备/参数，以及其他
        preservation(){
            if(this.rowDevItem == '设备信息'){
                // console.log("当前树形结构",this.nowagreementObj);
                // console.log("设备信息",this.deviceInfo);
                // var Regulations = this.thoroughfareOptionStatute.filter(item => item.id == this.deviceInfo.device_protocol_file)
                // console.log("规约",this.thoroughfareOptionStatute,Regulations);
                if(this.deviceInfo.device_name === ""){
                    this.$message({showClose: true,message: '设备名称不能为空',type: 'warning'});
                    return
                }
                
                if(this.deviceInfo.device_address === ""){
                    this.$message({showClose: true,message: '设备地址不能为空',type: 'warning'});
                    return
                }
                if(this.deviceInfo.break_count === ""){
                    this.$message({showClose: true,message: '中断次数不能为空',type: 'warning'});
                    return
                }
                if(this.deviceInfo.resend_count === ""){
                    this.$message({showClose: true,message: '重发次数不能为空',type: 'warning'});
                    return
                }
            
                if(!Number.isInteger(Number(this.deviceInfo.break_count))){
                    this.$message({showClose: true,message: '中断次数为[1-10整数]',type: 'warning'});
                    return
                }
                if(!Number.isInteger(Number(this.deviceInfo.resend_count))){
                    this.$message({showClose: true,message: '重发次数为[1-10整数]',type: 'warning'});
                    return
                }
                if(Number(this.deviceInfo.break_count) < 1 || Number(this.deviceInfo.break_count) > 10){
                    this.$message({showClose: true,message: '中断次数为[1-10整数]',type: 'warning'});
                    return
                }
                if(Number(this.deviceInfo.resend_count) < 1 || Number(this.deviceInfo.resend_count) > 10){
                    this.$message({showClose: true,message: '重发次数为[1-10整数]',type: 'warning'});
                    return
                }
                var d = {
                        "channel_number": Number(this.nowLeftRow.channel_number),
                        "device_number": Number(this.deviceInfo.device_number),
                        "device_name": this.deviceInfo.device_name,
                        "device_address": Number(this.deviceInfo.device_address),
                        "device_addressex": (this.deviceInfo.device_addressex),
                        "device_group": (this.deviceInfo.device_group === "" || this.deviceInfo.device_group === undefined) ? 0 : Number(this.deviceInfo.device_group),
                        "device_template": (this.deviceInfo.device_template === "" || this.deviceInfo.device_template === undefined) ? 0 : Number(this.deviceInfo.device_template),
                        "device_serial_type": (this.deviceInfo.device_serial_type === "" || this.deviceInfo.device_serial_type === undefined) ? 0 :Number( this.deviceInfo.device_serial_type),
                        "device_protocol":Number(this.deviceInfo.device_protocol),
                        // "device_protocol_file": Regulations[0].protocol_name+Regulations[0].suffix,
                        // "device_protocol_name": Regulations[0].name,
                        "resend_count": Number(this.deviceInfo.resend_count),
                        "break_count": Number(this.deviceInfo.break_count),
                        "run": this.deviceInfo.run ? 1 : 0,
                       "change": this.mychange ? 1 : 0,
                }
                if(this.nowOperatingDevice == '添加设备'){
                    // console.log("添加设备参数",d);
                    var ResData  = this.deviceArr.filter(item => item.device_name == this.deviceInfo.device_name)
                    if(ResData.length != 0){
                        this.$message({showClose: true,message: '此设备名称已存在！！',type: 'warning'});
                        return
                    }
                     this.diaisMask = true
                     addDevicechun(d).then(res => {
                        this.diaisMask = false
                        // console.log("新增设备",res);
                          if(res.code == 200){
                            this.addDecive = false
                            this.getDeviceconfigidleNumberfn()
                            this.$message({showClose: true,message: '添加设备成功',type: 'success'});
                            this.noeFlag = true
                            this.getList()
                            }else {
                                this.$message({showClose: true,message: '添加设备失败',type: 'error'});
                            }
                     }).catch(() => {
                         this.diaisMask = false
                     })
                }else {
                    //   console.log("修改设备参数",d);
                      d.device_id = this.deviceInfo.device_id
                      d.channel_number = this.deviceInfo.channel_number
                       this.diaisMask = true
                     editDevicechun(d).then(res => {
                           this.diaisMask = false
                        //    console.log("修改设备",res);
                          if(res.code == 200){
                             this.addDecive = false
                            this.$message({showClose: true,message: '修改设备成功',type: 'success'});
                            this.noeFlag = true
                            this.getList()
                            }else {
                                this.$message({showClose: true,message: '修改设备失败',type: 'error'});
                            }
                     }).catch(() => {
                         this.diaisMask = false
                     })
                }

            }else if(this.rowDevItem == '扩展参数'){
                //101扩展参数
               if(this.deviceInfo.devType == 1){
                //   console.log("101扩展参数ExtendedParameters101",this.ExtendedParameters101);
                  var d = {
                    'iec_type':1,
                    "device_id": this.deviceInfo.device_id,
                    "version": Number(this.ExtendedParameters101.version),
                    "public_address": Number(this.ExtendedParameters101.public_address),
                    "point_yx": this.ExtendedParameters101.point_yx,
                    "point_yc": this.ExtendedParameters101.point_yc,
                    "point_param": this.ExtendedParameters101.point_param,
                    "point_yk": this.ExtendedParameters101.point_yk,
                    "point_setting": this.ExtendedParameters101.point_setting,
                    "point_elect_level": this.ExtendedParameters101.point_elect_level,
                    "point_fjt": this.ExtendedParameters101.point_fjt,
                    "gate_limit": Number(this.ExtendedParameters101.gate_limit),
                    "balance": this.ExtendedParameters101.balance ? 1 : 0,
                    "yc_tran_type": Number(this.ExtendedParameters101.yc_tran_type),
                    "yx_tran_type": Number(this.ExtendedParameters101.yx_tran_type)
                  }
                //   console.log("接口需要的参数",d);
                 if(this.nowAddOrEditCanshu == '添加参数'){
                     this.isMask = true
                     addiec10xex(d).then(res => {
                           this.isMask = false
                          if(res.code == 200){
                            this.getExtendedParameters(this.deviceInfo.device_id,this.deviceInfo.devType)
                            this.$message({showClose: true,message: '保存成功',type: 'success'});
                          }else {
                               this.$message({showClose: true,message: '保存失败',type: 'error'});
                          }
                     }).catch(() => {
                          this.isMask = false
                     })
                 }else {
                      this.isMask = true
                      d.id = this.ExtendedParameters101.id
                      d.t0 = 0
                      d.t1 = 0
                      d.t2 = 0
                      d.t3 = 0
                      d.t4 = 0
                      d.k = 0
                      d.w = 0
                     editiec10xex(d).then(res => {
                           this.isMask = false
                          if(res.code == 200){
                               this.$message({showClose: true,message: '保存成功',type: 'success'});
                          }else {
                               this.$message({showClose: true,message: '保存失败',type: 'error'});
                          }
                     }).catch(() => {
                          this.isMask = false
                     })
                 }


               }else if(this.deviceInfo.devType == 2){ //104扩展参数
                // console.log("104扩展参数ExtendedParameters104",this.ExtendedParameters104);
                  var d = {
                    'iec_type':4,
                    "device_id": this.deviceInfo.device_id,
                    "version": Number(this.ExtendedParameters104.version),
                    "public_address": Number(this.ExtendedParameters104.public_address),
                    "point_yx": this.ExtendedParameters104.point_yx,
                    "point_yc": this.ExtendedParameters104.point_yc,
                    "point_param": this.ExtendedParameters104.point_param,
                    "point_yk": this.ExtendedParameters104.point_yk,
                    "point_setting": this.ExtendedParameters104.point_setting,
                    "point_elect_level": this.ExtendedParameters104.point_elect_level,
                    "point_fjt": this.ExtendedParameters104.point_fjt,
                    "gate_limit": Number(this.ExtendedParameters104.gate_limit),
                    "t0": Number(this.ExtendedParameters104.t0),
                    "t1": Number(this.ExtendedParameters104.t1),
                    "t2": Number(this.ExtendedParameters104.t2),
                    "t3": Number(this.ExtendedParameters104.t3),
                    "t4": Number(this.ExtendedParameters104.t4),
                    "k": Number(this.ExtendedParameters104.k),
                    "w": Number(this.ExtendedParameters104.w),
                    "yc_tran_type": Number(this.ExtendedParameters104.yc_tran_type),
                    "yx_tran_type": Number(this.ExtendedParameters104.yx_tran_type)
                  }
                    // console.log("接口需要的参数",d);
                 if(this.nowAddOrEditCanshu == '添加参数'){
                     this.isMask = true
                     addiec10xex(d).then(res => {
                           this.isMask = false
                          if(res.code == 200){
                               this.getExtendedParameters(this.deviceInfo.device_id,this.deviceInfo.devType) 
                               this.$message({showClose: true,message: '保存成功',type: 'success'});
                          }else {
                               this.$message({showClose: true,message: '保存失败',type: 'error'});
                          }
                     }).catch(() => {
                          this.isMask = false
                     })
                 }else {
                      this.isMask = true
                      d.id = this.ExtendedParameters104.id
                      d.balance = 1
                     
                     editiec10xex(d).then(res => {
                           this.isMask = false
                          if(res.code == 200){
                               this.$message({showClose: true,message: '保存成功',type: 'success'});
                          }else {
                               this.$message({showClose: true,message: '保存失败',type: 'error'});
                          }
                     }).catch(() => {
                          this.isMask = false
                     })
                 }

               }else if(this.deviceInfo.devType == 3){ //modbus扩展参数
            //    console.log("modbus扩展参数ExtendedParameters104",this.ExtendedParametersModbus);
                   var d = {
                        "device_id": this.deviceInfo.device_id,
                        "read_coil": Number(this.ExtendedParametersModbus.read_coil),
                        "read_input": Number(this.ExtendedParametersModbus.read_input),
                        "read_registor":Number( this.ExtendedParametersModbus.read_registor),
                        "read_keep": Number(this.ExtendedParametersModbus.read_keep),
                        "write_coil": Number(this.ExtendedParametersModbus.write_coil),
                        "write_registor": Number(this.ExtendedParametersModbus.write_registor)
                        }
                      if(this.nowAddOrEditCanshu == '添加参数'){
                            this.isMask = true
                            addModbusex(d).then(res => {
                                this.isMask = false
                                if(res.code == 200){
                                    this.getExtendedParameters(this.deviceInfo.device_id,this.deviceInfo.devType)
                                    this.$message({showClose: true,message: '保存成功',type: 'success'});
                                }else {
                                    this.$message({showClose: true,message: '保存失败',type: 'error'});
                                }
                            }).catch(() => {
                                this.isMask = false
                            })
                        }else {
                            this.isMask = true
                            d.id = this.ExtendedParametersModbus.id
                            editModbusex(d).then(res => {
                                this.isMask = false
                                if(res.code == 200){
                                    this.$message({showClose: true,message: '保存成功',type: 'success'});
                                }else {
                                    this.$message({showClose: true,message: '保存失败',type: 'error'});
                                }
                            }).catch(() => {
                                this.isMask = false
                            })
                        }
               }else if(this.deviceInfo.devType == 4){ //CDT扩展参数
            //    console.log("CDT扩展参数ExtendedParameters104",this.ExtendedParametersCDT);
                   var d = {
                        "device_id": this.deviceInfo.device_id,
                        "master_address": Number(this.ExtendedParametersCDT.master_address),
                        "slave_address": Number(this.ExtendedParametersCDT.slave_address),
                        "improtant_yc": Number(this.ExtendedParametersCDT.improtant_yc),
                        "minor_yc": Number(this.ExtendedParametersCDT.minor_yc),
                        "average_yc": Number(this.ExtendedParametersCDT.average_yc),
                        "yx": Number(this.ExtendedParametersCDT.yx),
                        "elect_level": Number(this.ExtendedParametersCDT.elect_level),
                        "yk": Number(this.ExtendedParametersCDT.yk),
                        "sync_word": this.ExtendedParametersCDT.sync_word
                    }
                      if(this.nowAddOrEditCanshu == '添加参数'){
                            this.isMask = true
                            addCdtcanshu(d).then(res => {
                                this.isMask = false
                                if(res.code == 200){
                                    this.getExtendedParameters(this.deviceInfo.device_id,this.deviceInfo.devType)
                                    this.$message({showClose: true,message: '保存成功',type: 'success'});
                                }else {
                                    this.$message({showClose: true,message: '保存失败',type: 'error'});
                                }
                            }).catch(() => {
                                this.isMask = false
                            })
                        }else {
                            this.isMask = true
                            d.id = this.ExtendedParametersCDT.id
                            editCdtcanshu(d).then(res => {
                                this.isMask = false
                                if(res.code == 200){
                                    this.$message({showClose: true,message: '保存成功',type: 'success'});
                                }else {
                                    this.$message({showClose: true,message: '保存失败',type: 'error'});
                                }
                            }).catch(() => {
                                this.isMask = false
                            })
                        }


               }
            }else {
                //保存就是排序
                this.ForwardVariableTableCopy.forEach(item => {
                    item.cofficient = item.cofficient != "" ? Number(item.cofficient) : 0
                    item.device = this.nowLeftRow.device_number
                })
                var variablesArr = {
                    'transfer_type_id':this.nowdeviceItemObj.id,
                    'variables':this.ForwardVariableTableCopy
                }

                this.isMask = true
                saveForward(variablesArr).then(res => {
                    //  console.log("保存转发变量",res);
                    this.isMask = false
                    if(res.code == 200){
                        this.getZhuanfaBianliang()
                        this.$refs.multipleTable.clearSelection()
                        this.$message({showClose: true,message: '保存成功',type: 'success'});
                    }else {
                        this.isMask = false
                        this.$message.error('保存失败！')
                    }
                    
                })

            }
        },
        //getAgreementListfn
        getAgreementListfn(){
            this.drawer = true
        },
        //查询转发协议
        getAgreementList(){
            // this.drawer = true
             this.diaisMask = true
            getAgreement().then(res => {
            // console.log("获取转发协议",res);
            this.agreementTree[0].children = res
              this.diaisMask = false
            }).catch(() => {
              this.diaisMask = false
           })
        },
        //打开添加/修改转发协议
        openAgreement(type,row){
            this.AgreementType = type
            // console.log("row",row);
            if(type == '添加转发协议'){
                 this.agreemenName = ""
                 this.agreemenRemarks = ""
            }else {
                 if(row.id == '000001111'){
                    this.$message({showClose: true,message: '此项不能进行操作！！',type: 'warning'});
                    return
                 }
                 this.AgreementType = `修改转发协议(${row.name})`
                 this.AgreementRow = row
                 this.agreemenName = row.name
                 this.agreemenRemarks = row.remark
            }
            this.dialogflag = true
            
        },
        //添加转发协议
        addAgreement(){
             var d = {
                "name": this.agreemenName,
                "remark": this.agreemenRemarks
            }
            if(this.agreemenName === ""){
                 this.$message({showClose: true,message: '协议名称不能为空！',type: 'warning'});
                return
            }
            if(this.AgreementType == '添加转发协议'){
               this.diaisMask = true
                    addAgreemntapi(d).then(res => {
                        if(res.code == 200){
                            this.dialogflag = false
                            this.getAgreementList()
                            this.noeFlag = false
                            this.getList()
                            this.$message({showClose: true,message: '新增成功',type: 'success'});
                        }else {
                             this.$message({showClose: true,message: '新增失败',type: 'error'});
                        }
                        this.diaisMask = false
                    }).catch(() => {
                        this.diaisMask = false
                })
            }else {//修改转发协议
               d.id = this.AgreementRow.id
                this.diaisMask = true
                 editAgreementapi(d).then(res => {
                    if(res.code == 200){
                            this.dialogflag = false
                            this.getAgreementList()
                            this.noeFlag = false
                            this.getList()
                            this.$message({showClose: true,message: '修改成功',type: 'success'});
                        }else {
                             this.$message({showClose: true,message: '修改失败',type: 'error'});
                        }
                      this.diaisMask = false
                 }).catch(() => {
                        this.diaisMask = false
                })
            }
        },
        //删除转发协议
        delAgreement(row){
             this.$confirm(`是否要删除此项？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
               delAgreementapi(row.id).then(res => {
                //   console.log("删除",res);
                  if(res.code == 200){
                    this.$message({showClose: true,message: '删除成功',type: 'success'});
                    this.getAgreementList()
                    this.getList()
                  }else {
                    this.$message.error('删除失败！！')
                  }
               }).catch(error => {
                    this.$message.error('删除失败！！')
               })
              
        
                      
            }).catch(() => {
              // ...
            });
        },
        //查询转发类型
        nodeClickzhuanfa(row){
            this.AgreementRow = row
            this.getforwardingTypeList()
        },
        //查询转发类型
        getforwardingTypeList(){
              this.diaisMask = true
              forwardingTypeList(this.AgreementRow.id).then(res => {
                // console.log("res",res);
                if(res != undefined){
                    this.TypeTable = res
                }
                 this.diaisMask = false
              }).catch(() => {
              this.diaisMask = false
              })
        },
        //打开添加转发类型弹窗
        openAgreementType(type,row){
            if(this.AgreementRow.id == undefined){
                 this.$message({showClose: true,message: '请选择协议',type: 'warning'});
                return
            }
            this.AgreementType = type
            if(type == '添加转发类型'){
                 this.typeCode = ""
                 this.typeName = ""
                 this.typeQidian  = ""
            }else {
                 this.AgreementType = `修改转发类型(${row.name})`
                 this.AgreementRowZhuanfa = row
                 this.typeCode = row.number
                 this.typeName = row.name
                 this.typeQidian  = row.start_point
            }
            this.zhuandialogflag = true
        },
        
        //确定添加修改转发类型弹窗
        addAgreementType(){
            if(this.typeName === ""){
                this.$message({showClose: true,message: '类型名称不能为空',type: 'warning'});
                return
            }
            if(this.typeCode === ""){
                this.$message({showClose: true,message: '类型编号不能为空',type: 'warning'});
                return
            }
            if(this.typeQidian === ""){
                this.$message({showClose: true,message: '起始点号不能为空',type: 'warning'});
                return
            }
            // 使用 reduce 方法找出 no 属性的最大值
            var maxAge = this.TypeTable.reduce((max, item) => {
            return Math.max(max, item.no);
            }, -Infinity);

            // console.log(maxAge); // 输出 30
            var d = {
                "name": this.typeName,
                "number": Number(this.typeCode),
                "start_point": Number(this.typeQidian),
                "type_id": this.AgreementRow.id
            }
            
            
            if(this.AgreementType == '添加转发类型'){
               this.diaisMask = true
               d.no = (maxAge+1)
                    addAgreemntapitype(d).then(res => {
                        this.diaisMask = false        
                        if(res.code == 200){
                            this.$message({showClose: true,message: '添加成功',type: 'success'});
                            this.getforwardingTypeList()
                            this.zhuandialogflag = false
                        }else {
                             this.$message.error('添加失败')
                        }
                    }).catch(() => {
                        this.diaisMask = false
                })
            }else {//修改转发类型
                d.id = this.AgreementRowZhuanfa.id
                d.no = this.AgreementRowZhuanfa.no
                editAgreementapitype(d).then(res => {
                        this.diaisMask = false
                        if(res.code == 200){
                          this.$message({showClose: true,message: '修改成功',type: 'success'});
                                this.getforwardingTypeList()
                                this.zhuandialogflag = false
                        }else {
                              this.$message.error('修改失败！！')
                        }
                    }).catch(() => {
                        this.diaisMask = false
                })
            }
        },

        //删除转发协议类型
        delAgreementtype(row){
             this.$confirm(`是否要删除此项？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
               
               delAgreementapitype(row.id).then(res => {
                //   console.log("删除",res);
                  if(res.code == 200){
                     
                     this.$message({showClose: true,message: '删除成功',type: 'success'});
                     this.getforwardingTypeList()
                  }else {
                     this.$message.error('删除失败！！')
                  }
               }).catch(error => {
                    this.$message.error('删除失败！！')
               })
              
        
                      
            }).catch(() => {
              // ...
            });
        },

        //参数tav切换
        rowDevItemfn(row){
            this.rowDevItem = row
            if(row != '扩展参数' && row != '设备信息'){
                this.nowdeviceItemObj = this.deviceItemArr.filter(item => item.name == row)[0]
                // console.log("查看转发类型",this.nowdeviceItemObj);
                this.currentPage2 = 1 
                this.currentRow = {}
                this.getZhuanfaBianliang()
            }
        },
        //获取转发变量
        getZhuanfaBianliang(){
            this.isMask = true
            var d = {
                 typeid:this.nowdeviceItemObj.id,
                 deviceid:this.nowLeftRow.device_number
            }
             findForwardVariableList(d).then(res => {
                     this.isMask = false
                     if(res != undefined){
                         this.ForwardVariableTableCopy = JSON.parse(JSON.stringify(res)) 
                         this.ForwardVariableTableCopy.forEach(item => {
                             item.editCofficient = false
                         })
                         this.ForwardVariableTable = this.getCurrentPageData(this.ForwardVariableTableCopy,this.currentPage2,100)
                         this.total2 = this.ForwardVariableTableCopy.length
                         var findArr = []
                         this.collecVariablTable.forEach(item => {
                            item.isDisabled = true
                             findArr = this.ForwardVariableTableCopy.filter(tt => tt.variable_id == item.id)
                            if(findArr.length != 0){
                                 item.isDisabled = false
                            }
                         })
                         this.collecVariablTableCopy.forEach(item => {
                            item.isDisabled = true
                             findArr = this.ForwardVariableTableCopy.filter(tt => tt.variable_id == item.id)
                            if(findArr.length != 0){
                                 item.isDisabled = false
                            }
                         })
                     }
            })
        },
       
        //获取采集通道
        getfindchannelconfigAll(){
            findchannelconfigAll().then(res => {
            if(res != undefined){
                res.forEach(item => {
                     item.treeName = item.channel_name
                     item.mytype = 'channel'
                     item.myid = item.channel_number
                     item.children = this.deviceArr.filter(tt => tt.channel_number == item.channel_number)
                     item.children.forEach(tt => {
                         tt.myid = item.channel_number+String(tt.device_number)
                     })
                })
                this.gatherDataList[0].children = res
                getChannelAndDeviceState().then(result => {
                    if(res != undefined){
                        this.channelstateList = result.filter(item => item.name.includes('channelstate'))
                        this.devicestateList = result.filter(item => item.name.includes('devicestate'))
                        //  console.log("result",result);

                     }
                })
                

            }
            
            }).catch(() => {
              })
        },
        //获取所有设备
        getDeviceListData(){
              getDeviceList().then(res => {
                   if(res != undefined){
                    res.forEach(item => {
                         item.treeName = item.device_name
                         item.children = []
                         item.mytype = 'device'
                    })
                       this.deviceArr = res
                       this.getfindchannelconfigAll()
                      
                   }
              }).catch(() => {
              })
        },
       //采集通道树形结构点击
        treeClick(row){
            //  console.log("树形",row);
             this.nowcollecDeviceItem = row
             if(row.mytype == 'device'){
                if(row.treeName == 'channelstate' && row.myid == '1000000000003'){
                    var findArr = []
                    this.channelstateList.forEach(item => {
                        item.isDisabled = true
                        findArr = this.ForwardVariableTableCopy.filter(tt => tt.variable_id == item.id)
                        if(findArr.length != 0){
                            item.isDisabled = false
                        }
                    })
                    this.currentPage = 1 
                    this.collecVariablTableCopy = JSON.parse(JSON.stringify(this.channelstateList)) 
                    this.collecVariablTable = this.getCurrentPageData(this.collecVariablTableCopy,this.currentPage,100)
                    this.total = this.collecVariablTableCopy.length
                    return
                }
                if(row.treeName == 'devicestate' && row.myid == '1000000000004'){
                    var findArr = []
                    this.devicestateList.forEach(item => {
                        item.isDisabled = true
                        findArr = this.ForwardVariableTableCopy.filter(tt => tt.variable_id == item.id)
                        if(findArr.length != 0){
                            item.isDisabled = false
                        }
                    })
                    this.currentPage = 1 
                    this.collecVariablTableCopy = JSON.parse(JSON.stringify(this.devicestateList)) 
                    this.collecVariablTable = this.getCurrentPageData(this.collecVariablTableCopy,this.currentPage,100)
                    this.total = this.collecVariablTableCopy.length
                    return
                }
                this.isMask = true
                 getVariablesDevice(row.device_id).then(res => {
                      this.isMask = false
                      if(res != undefined){
                        var RESDATA = res
                        var findArr = []
                        RESDATA.forEach(item => {
                            item.isDisabled = true
                            findArr = this.ForwardVariableTableCopy.filter(tt => tt.variable_id == item.id)
                            if(findArr.length != 0){
                                 item.isDisabled = false
                            }
                        })
                        this.currentPage = 1 
                        this.collecVariablTableCopy = JSON.parse(JSON.stringify(RESDATA)) 
                        this.collecVariablTable = this.getCurrentPageData(this.collecVariablTableCopy,this.currentPage,100)
                        this.total = this.collecVariablTableCopy.length
                        // console.log("转发变量",this.ForwardVariableTable);
                      }
                 }).catch(() => {
                     this.isMask = false
                 })
             }
        },
        checkSelectable(row){
            return row.isDisabled
        },
        //选择采集的变量
        handleSelectionChange(val){
           this.collecVariabData = val
        //    console.log("this.collecVariabData",this.collecVariabData);
        },
        //选择转发得变量
        handleSelectionChange2(val){
            this.forwardVariabData = val
        },
        //添加转发变量
        addForwardingVariables(){
           
            // channel_number 原始通道号
            // device_number 原始设备号
            if(this.collecVariabData.length == 0){
                  this.$message({showClose: true,message: '请选择需要添加的变量',type: 'warning'});
                  return
            }
            var dd = []
            // this.ForwardVariableTableCopy
            // show_number
            this.collecVariabData.forEach((item,index) => {
                 dd.push({
                    "variable_id": item.id,
                    "show_number": this.ForwardVariableTableCopy.length + index,
                    "data_number": item.data_number,
                    "cofficient": 1,
                    "data_type": item.data_type,
                    "from_channel": item.channel_number,
                    "from_device": item.device_number,
                    "from_type": 0,
                    "area": Number(this.nowdeviceItemObj.id),
                    "variable_name": item.name,
                    "type_no":this.nowdeviceItemObj.channel_number,
                    'channel':this.nowLeftRow.channel_number,
                    'device':this.nowLeftRow.device_number,
                    'fullName':item.fullName
                 })
            })
            // channel 自身的通道序号
            // device 自身的设备序号
            this.isMask = true
            saveForwardVariableList(dd).then(res => {
                if(res.code == 200){
                      this.getZhuanfaBianliang()
                      this.$refs.multipleTable.clearSelection()
                      this.$message({showClose: true,message: '添加成功',type: 'success'});
                }else {
                    this.isMask = false
                      this.$message.error('添加失败！')
                }
            }).catch(() => {
                 this.isMask = false
            })
        },
        //删除转发变量
        delForwardVariabfn(){
            //  this.forwardVariabData
            if(this.forwardVariabData.length == 0){
                 this.$message({showClose: true,message: '请选择需要删除的变量',type: 'warning'});
                  return
            }
            this.$confirm(`是否要删除此项？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
                var idArr = []
                this.forwardVariabData.forEach(item => {
                    if(item.id){
                        idArr.push(item.id)
                    }
                })
                this.isMask = true
                delForwardVariableList(idArr).then(res => {
                    if(res.code == 200){
                        this.getZhuanfaBianliang()
                        this.$message({showClose: true,message: '删除成功',type: 'success'});
                    }else {
                        this.isMask = false
                        this.$message.error('删除失败！')
                    }
                }).catch(() => {
                     this.isMask = false
                })
                             
            }).catch(() => {
              // ...
            });
         
        },
        //选中需要移动的转发变量
        handleCurrentChange(val) {
            this.currentRow = val;
        },
        //上移转发变量
        variabMoveUp(){
            if(JSON.stringify(this.currentRow) === '{}'){
                this.$message({showClose: true,message: '请选择需要移动的转发变量',type: 'warning'});
                return
            }
            var myindex = this.ForwardVariableTableCopy.findIndex(item => item.id == this.currentRow.id && item.variable_name == this.currentRow.variable_name)
            if(myindex == 0){
                 this.$message({showClose: true,message: '此项是第一行，不可再上移',type: 'warning'});
                 return
            }
            this.ForwardVariableTableCopy = this.moveItemUp(this.ForwardVariableTableCopy,myindex)
            this.ForwardVariableTable = this.getCurrentPageData(this.ForwardVariableTableCopy,this.currentPage2,100)
        },
        moveItemUp(items, index) {
            // if (index <= 0) return items;
            const newItems = [...items];
            [newItems[index-1], newItems[index]] = [newItems[index], newItems[index-1]];
            return newItems;
        },
        //下移转发变量
        variabMoveDown(){
            if(JSON.stringify(this.currentRow) === '{}'){
                this.$message({showClose: true,message: '请选择需要移动的转发变量',type: 'warning'});
                return
            }
            var myindex = this.ForwardVariableTableCopy.findIndex(item => item.id == this.currentRow.id && item.variable_name == this.currentRow.variable_name)
            if(myindex == this.ForwardVariableTableCopy.length - 1){
                 this.$message({showClose: true,message: '此项是最后一行，不可再下移',type: 'warning'});
                 return
            }
            this.ForwardVariableTableCopy = this.moveItemDown(this.ForwardVariableTableCopy,myindex)
            this.ForwardVariableTable = this.getCurrentPageData(this.ForwardVariableTableCopy,this.currentPage2,100)
        },
        moveItemDown(items, index) {
            // if (index >= items.length - 1) return items;
            const newItems = [...items];
            [newItems[index], newItems[index+1]] = [newItems[index+1], newItems[index]];
            return newItems;
        },
        handleSizeChangejiao(){
            
        },
        handleCurrentChangejiao(val){
           this.currentPage=val;
           this.collecVariablTable = this.getCurrentPageData(this.collecVariablTableCopy,this.currentPage,100)
        },
        // ForwardVariableTable
        handleCurrentChangejiao2(val){
           this.currentPage2=val;
           this.ForwardVariableTable = this.getCurrentPageData(this.ForwardVariableTableCopy,this.currentPage2,100)
        },
        getCurrentPageData(dataList, page, size) {
            // 计算并返回当前页数据
            var res = dataList.slice((page-1)*size, page*size)
            return res
        },
        //导出转发变量
        exportDataExcel(){
            var tableData11 = []
            // console.log("转发类型",this.deviceItem);
            // console.log("转发类型Arr",this.deviceItemArr);
            // console.log("导出",this.ForwardVariableTableCopy);
            // return
            if(this.ForwardVariableTableCopy.length == 0){
                this.$message({showClose: true,message: '转发变量为空，无需导出',type: 'warning'});
                return
            }
            this.ForwardVariableTableCopy.forEach(item => {
                 tableData11.push({
                    '点号':String(item.data_number),
                    '变量名称':String(item.fullName),
                    '系数':String(item.cofficient),
                 })
            })
             // 1. 创建工作簿
            const workbook = XLSX.utils.book_new();

            // 2. 将数组对象转换为工作表
            const worksheet = XLSX.utils.json_to_sheet(tableData11);

             // 自定义列宽
            worksheet['!cols'] = [
                { wch: 10 }, 
                { wch: 20 },  
                { wch: 10 },  
            ];

            // 3. 将工作表添加到工作簿
            XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");

            // 4. 生成 Excel 文件并下载
            const excelBuffer = XLSX.write(workbook, { bookType: "xlsx", type: "array" });
            const blob = new Blob([excelBuffer], { type: "application/octet-stream" });
            saveAs(blob, "转发变量.xlsx");
        },
        //导入转发变量
         openDaorufnxls(){
            this.$confirm(`导入将会冲掉原来的，确定导入？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
                 this.$refs.dianfileInput222.click();
                             
            }).catch(() => {
              // ...
            });
           
            // this.daorushebeimuban = true
        },
        handleFileUploadxls(event) {
        const file = event.target.files[0];
        if (!file) return;

        const reader = new FileReader();
        reader.onload = (e) => {
            const data = new Uint8Array(e.target.result);
            const workbook = XLSX.read(data, { type: 'array' });

            // 获取第一个工作表
            const firstSheetName = workbook.SheetNames[0];
            const worksheet = workbook.Sheets[firstSheetName];

            // 处理合并单元格（关键步骤）
            if (worksheet['!merges']) {
            worksheet['!merges'].forEach((merge) => {
                const startCell = XLSX.utils.encode_cell({ r: merge.s.r, c: merge.s.c });
                const endCell = XLSX.utils.encode_cell({ r: merge.e.r, c: merge.e.c });
                
                // 将合并区域的值统一为左上角单元格的值
                for (let row = merge.s.r; row <= merge.e.r; row++) {
                    for (let col = merge.s.c; col <= merge.e.c; col++) {
                        const cellAddress = XLSX.utils.encode_cell({ r: row, c: col });
                        if (!worksheet[cellAddress]) {
                        worksheet[cellAddress] = { ...worksheet[startCell] };
                        }
                    }
                }
            });
            }
            // 转换为 JSON
            this.jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: '' })
            // console.log("导入转发变量的xls数据",this.jsonData);
            this.processingData()
            //以上需要删除的
            this.$refs.dianfileInput222.value = ""
            
        };
        reader.readAsArrayBuffer(file);
        },
        //处理导入进来的变量数据
        processingData(){
            // console.log("this.nowdeviceItemObj.id",this.nowdeviceItemObj.id);
            var variablesArr = {
                'transfer_type_id':this.nowdeviceItemObj.id,
                'variables':[]
            }
            var filterArr = []
            this.jsonData.forEach(item => {
                if(item['变量名称'] != ""){
                    filterArr = this.allVariables.filter(tt => tt.fullName == item['变量名称'])
                    if(filterArr.length != 0){
                         variablesArr.variables.push({
                            "area": this.nowdeviceItemObj.id,
                            "cofficient": item['系数'] != "" ? Number(item['系数']) : 1,
                            "data_number": filterArr[0].data_number,
                            "data_type": filterArr[0].data_type,
                            "from_channel": filterArr[0].channel_number,
                            "from_device": filterArr[0].device_number,
                            "from_type": 0,
                            'fullName':filterArr[0].fullName,
                            "variable_id": filterArr[0].id,
                            "variable_name": filterArr[0].name,
                            'device':this.nowLeftRow.device_number,
                        })
                    }
                }
            })
            //重新赋值点号
            variablesArr.variables.forEach((item,index) => {
                item.show_number = index
            })
             this.isMask = true
            saveForward(variablesArr).then(res => {
                //  console.log("保存转发变量",res);
                 this.isMask = false
                 if(res.code == 200){
                      this.getZhuanfaBianliang()
                      this.$refs.multipleTable.clearSelection()
                      this.$message({showClose: true,message: '导入成功',type: 'success'});
                 }else {
                      this.isMask = false
                      this.$message.error('保存失败！')
                 }
                
            })
            

        },
        //导出模版专用
        templateSpecific(){
            if(this.ForwardVariableTableCopy.length == 0){
                this.$message({showClose: true,message: '转发变量为空，无需导出',type: 'warning'});
                return
            }
            console.log("rowDevItem",this.allVariables);
            const dataArray = [];
            this.ForwardVariableTableCopy.forEach(item => {
                 dataArray.push(item.fullName)
            })
             // 假设这是你的数组
            
            
            // 将数组转换为每行一个元素的字符串
            const txtContent = dataArray.join('\n');
            
            // 创建 Blob 对象
            const blob = new Blob([txtContent], { type: 'text/plain' });
            
            // 创建下载链接
            const link = document.createElement('a');
            link.href = URL.createObjectURL(blob);
            link.download = this.rowDevItem+'导出模版专用.txt'; // 设置文件名
            
            // 触发下载
            document.body.appendChild(link);
            link.click();
            
            // 清理
            document.body.removeChild(link);
            URL.revokeObjectURL(link.href);
        },

      
        
    },
};
</script>

<style lang="scss" scoped>
.shebeidivdiv .leftname{
     min-width:90px !important;
}

.mytitle {
                 flex: 1;
                 height: 32px;
                 background-color: #F0F5FF;
                 border-radius: 4px;
                 display: flex;
                 align-items: center;
                 color: #000;
               //   font-weight: bold;
                 font-size: 15px;
                 margin-right: 20px;
                 span {
                     display: inline-block;
                     width: 3px;
                     height: 18px;
                     background-color: #2178F1;
                     margin-left: 12px;
                     margin-right: 6px;
                     border-radius: 3px;
                 }
             }
 .con2 {
          width: 100%;
          height: calc(100% - 110px);
          display: flex;
          justify-content: center;

          .con2-titile {
            font-size: 16px;
            color: #1A1A1A;
            margin-top: 24px;
            display: flex;
            align-items: center;
            span {
                 display: inline-block;
                 flex: 1;
                 height: 1px;
                 margin-left: 10px;
                 background-color: #E6E6E6;
            }
          }
          .xiaoti {
            font-size: 15px;
             padding-left: 15px;
             box-sizing: border-box;
            color: #666666;
          }

          .con2-item {
            margin-top: 24px;
            display: flex;
            align-items: center;
            height: 32px;

            .item-left {
              width: 160px;
              white-space: nowrap;
              text-align: right;
              color: #1A1A1A;
              font-size: 12px;
            }

            :deep(.el-radio) {
              position: relative;
              top: 1px;
              margin-right: 20px;
            }

            :deep(.el-radio__label) {
              padding-left: 4px;
            }


            :deep(.el-radio__input.is-checked .el-radio__inner) {
              background-color: #fff;
              border-color: #0052CC;

            }

            :deep(.el-radio__inner ){
              border-color: #999999;
            }

            :deep(.el-radio__inner::after) {
              width: 8px;
              height: 8px;
              background-color: #0052CC;
            }
          }
          .ttttt {
              margin-top: 10px;
              .item-left{
                  width: 100px;
            }
            span {
                 font-size: 12px;
                 color: #666;
            }
        }
 }
 .channelinfobox {
     width: 100%;
    //  height: 150px;
     .infoitems {
         width: 100%;
         display: flex;
         margin-bottom: 12px;
         .items {
             display: flex;
             align-items: center;
             flex: 1;
             .leftname {
                width: 70px;
                min-width: 70px;
                text-align: right;
                white-space: nowrap;
             }
             .elinputdisabled {
                //  height: 28px;
             }
             :deep(.el-select) {
                 flex: 1;
                 .el-input__inner {
                    background-color: #fff !important;
                    border-color: #DCDFE6 !important;
                     color: #606266 !important;
                     height: 28px !important;
                 }
             }
        
         }
         .itemright {
             margin-right: 20px;
         }
     }
 }
 .deviceinfobox {
    .leftname {
         width: 85px !important;
         min-width: 85px !important;
    }
 }
  .radio-type {
                     width: 100%;
                    //  height: 30px;
                     display: flex;
                     align-items: center;
                     flex-wrap: wrap;
                      .myname {
                            width: 60px;
                            text-align: right;
                            font-size: 12px;
                            color: #666666;
                            // margin-right: 8px;
                            position: relative;
                         }
                     .left-type {
                         display: flex;
                        //  align-items: center;
                        //  flex-wrap: wrap;
                        //  margin-right: 40px;
                         .myname {
                            top: 7px;
                            white-space: nowrap;
                         }
                     }
                     .myradio {
                        display: flex;
                         align-items: center;
                         flex-wrap: wrap;
                     }
                     .right-tongdao {
                         display: flex;
                         align-items: center;
                         position: relative;
                         top: -1px;
                         .tong {
                             margin-left: 4px;
                             color: #1A1A1A;
                             font-size: 12px;
                         }
                     }
                }
 .shezhi-item {
            display: flex;
            align-items: center;
            margin-top: 24px;

            .less-name {
              width: 156px;
              font-size: 12px;
              color: #1A1A1A;
              white-space: nowrap;
              text-align: right;
            }

            .left-input {
              margin-right: 60px;
              display: flex;
              align-items: center;
            }

            .right-input {
              display: flex;
              align-items: center;
            }
}


.quxiao {
                         margin-left: 8px;
                         color: #666666;
                         background-color: #fff;
                         border: 1px solid #cccccc;
}
.delmydiodiv {
     display: flex;
     align-items: center;
     justify-content: center;
     margin-top: 20px;
     margin-bottom: 10px;
     span {
        color: #1A1A1A;
     }
}
.mydiodiv1 {
     display: flex;
      .dioleftname {
         white-space: nowrap;
         margin-right: 8px;
         color: #666666;
     }
     .rightname {
         white-space: nowrap;
         color: #666666;
         margin-left:8px
     }
     .dioleftname1 {
        width: 55px;
        text-align: right;
     }
}
.custom-tree-node {
     font-size:12px;
     color:#1a1a1a;
     width: 100%;
     display: flex;
     align-items: center;
     justify-content: space-between;
     i {
         transform: rotateZ(90deg);
         color: #999999;
         font-size: 14px;
         margin-right: 8px;
     }
}
.mydiodiv {
     display: flex;
     align-items: center;
     .dioleftname {
         white-space: nowrap;
         margin-right: 8px;
         color: #666666;
     }
     .rightname {
         white-space: nowrap;
         color: #666666;
         margin-left:8px
     }
     .dioleftname1 {
        width: 55px;
        text-align: right;
     }
}
.qucolor {
    border: 1px solid #CCCCCC;
    color: #666666;
}

:deep(.el-drawer ){
    width: 800px !important;
}
:deep(.el-drawer__header) {
     height: 56px;
    padding: 0px 20px;
    border-bottom: 1px solid #E6E6E6;
    margin-bottom: 0px;
    span {
       font-size: 14px;
       color: #1a1a1a;
    }
}
:deep(.el-drawer__close-btn .el-icon-close ){
      font-size: 24px !important;
      color: #666666;
}
 .collectionchannel {
    position: relative;
     .con {
         width: 100%;
         height: 100%;
        //  background-color: #fff;
        display: flex;
        .con-left {
            position: relative;
            // width: 120px;
             min-width: 260px;
             max-width: 260px;
             height: 100%;
             background-color: #fff;
             margin-right: 8px;
             padding: 12px 4px 12px 12px;
             box-sizing: border-box;
             font-size: 12px;
             .nodeoperation {
                 position: absolute;
                 top: 20px;
                 left: 160px;
                 width: 140px;
                 background-color: #1A1A1A;
                 border-radius: 4px;
                 z-index: 100;
                 padding-top: 8px;
                 box-sizing: border-box;

                      div {
                        width: 100%;
                        height: 25px;
                        font-size: 13px;
                         color: #fff;
                        cursor: pointer;
                        padding-left: 20px;
                        box-sizing: border-box;
                        line-height: 25px;
                        margin-bottom: 8px;
                        &:hover {
                            background-color: #2178F1;
                        }
                    }
                 
                

             }
        }
        .con-right-all {
           width: calc(100% - 268px);
             height: 100%;
              background-color: #fff;
            position: relative;
            .xieyililist {
                 width: 100%;
                 height: 100%;
                 padding: 20px;
                 box-sizing: border-box;
                 .topdisflex {
                     width: 100%;
                     display: flex;
                     align-items: center;
                     justify-content: space-between;
                     margin-bottom: 15px;
                 }
                 .mytable {
                     width: 100%;
                     height: calc(100% - 45px);
                 }
            }
           .right-top{
                width: 100%;
                height: 42px;
                display: flex;
                align-items: center;
                font-size: 14px;
                padding-left: 12px;
                box-sizing: border-box;
                border-bottom: 1px solid #E6E6E6;
           }
           .dev-right-top {
             width: 100%;
             display: flex;
             height: 30px;
             box-sizing: border-box;
             border-bottom: 1px solid #E6E6E6;
              padding-left: 12px;
              margin-top: 12px;
             .top-item {
                 width: 108px;
                 text-align: center;
                 border-bottom: 2px solid transparent;
                 font-size: 14px;
                 color: #666666;
                 cursor: pointer;
                 &.active {
                      border-bottom-color: #2178F1;
                      color: #2178F1;
                      font-weight: bold;
                 }
             }
           }
           
           .right-content {
             display: flex;
             justify-content: center;
             padding: 20px 0px;
            //  border-bottom: 1px dashed #D6D6D6;
             .content-left {
                 margin-right: 60px;
             }
           }
           .content-item {
             width: 5.2rem;
             height: 0.44rem;
             display: flex;
             align-items: center;
             .item-input {
                 width:100%
             }
             :deep(.el-input__inner) {
                 width:100%;
                 height: 28px;
                 line-height: 28px;
                 font-size: 12px;
                 color: #1A1A1A;
             }
             :deep(.el-input__icon) {
                 line-height: 28px;
             }
             .item-name {
                  min-width: 72px;
                  text-align: right;
                  margin-right: 8px;
                  white-space: nowrap;
                    color: #1A1A1A;
             }
             .teshu::before {
                 content: "*";
                 color: #f56c6c;
                margin-right: 4px;
                font-size: 15px;
             }
             .tips {
                 margin-left: 8px;
                 color: #666666;
                 white-space: nowrap;
             }
           }
           .right-parameter {
            .parameter-top {
                 font-size: 14px;
                 color: #666666;
                 margin-bottom: 20px;
            }
               .content-left {
                 margin-right: 0px;
               }
               .item-name {
                   width: 110px;
               }
           }
           .other-con {
              width: 100%;
              height: calc(100% - 40px);
              padding: 0px 12px 0px 12px;
              box-sizing: border-box;
              display: flex;

              .other-left {
                 min-width: 230px;
                 width: 230px;
                 height: 100%;
                 box-sizing: border-box;
                 padding-top: 20px;
                 border-right: 1px solid #D8D8D8;
                 .other-type {
                     font-size: 12px;
                     color: #1A1A1A;
                     margin-bottom: 12px;
                 }
                 .other-tree {
                     width: 100%;
                     height: calc(100% - 38px);
                     padding-right: 12px;
                     box-sizing: border-box;
                     
                 }
                 
              }
              .other-right {
                 width: calc(100% - 242px);
                 height: calc(100% - 55px);
                 margin-left: 12px;
                 padding-top: 20px;
                 box-sizing: border-box;
                 display: flex;
              }

           }
           .initial-table {
              width: calc(40% - 36px);
              height: 100%;
              padding-top: 28px;
              box-sizing: border-box;
              .mytablemy {
                 width: 100%;
                 height: calc(100% - 57px);
              }
           }
           .bot-btn {
             width: 100%;
             height: 47px;
            //  margin-top: 44px;
             border-top: 1px solid #E6E6E6;
             .scr-div {
                width: 100%;
                height: 48px;
                display: flex;
                align-items: center;
                justify-content: space-between;
             }
             
        }
           .operate-btn {
             width: 72px;
             height: 176px;
             margin: 0px 30px;
             margin-top: 157px;
             .unify-btn {
                min-width: 72px;
                height: 28px;
                cursor: pointer;
                border-radius: 4px;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 12px;
                img {
                     margin-left: 4px;
                }
             }
             .top-btn { 
                 width: 100%;
                 .add-btn {
                     background-color: #2178F1;
                     color: #fff;
                     margin-bottom: 12px;
                 }
                 .del-btn {
                     background-color: #F3440D;
                     color: #fff;
                     margin-bottom: 40px;
                 }

             }
             .bottom-btn {
                  width: 100%;
                 .moveup-btn {
                     border: 1px solid #E6E6E6;
                     color: #666666;
                     margin-bottom: 12px;
                 }
                 .down-btn {
                     border: 1px solid #E6E6E6;
                     color: #666666;
                 }
             }

           }
           .complete  {
              width: calc(60% - 100px);
              
             .other-type {
                 width: 100%;
                 font-size: 12px;
                 color: #1a1a1a;
             }
           }

           .teshuinput {
               :deep(.el-input__inner ){
                 width: 1.2rem;
             }
           }
           .right-line {
               border-bottom: 1px dashed #D6D6D6;
               margin: 0px 12px;
           }
           .right-bo-con {
              display: flex;
              justify-content: center;
               .content-left {
                 margin-right: 60px;
             }
              .bo-con {
                 margin-top: 0.4rem;
              }
              .bocon-top {
                 margin-bottom: 20px;
                 display: flex;
                 .top-item {
                     height: 28px;
                     padding: 0px 12px;
                     text-align: center;
                     line-height: 28px;
                     border-radius: 20px;
                     margin-right: 12px;
                     font-size: 13px;
                     cursor: pointer;
                    &.active {
                         background-color: #e7f0ff;
                         color: #2178F1;
                    }
                 }
                 

              }
              .bo-con-items {
                 display: flex;
              }
           }
        }
         .bottomoperate-btn {
                 width: 72px;
                 height: 28px;
                 display: flex;
                 align-items: center;
                 justify-content: center;
                 border-radius: 4px;
                 margin-right: 8px;
                 font-size: 12px;
                 cursor: pointer;
             }
             .solidcolor {
                  background-color: #2178F1;
                  color: #fff;
             }
        .con-bottom {
            width: 100%;
            position: absolute;
            bottom: 0px;
            right: 0px;
             text-align: center;
            //  padding: 12px 0px;
            height: 54px;
             border-top: 1px solid #E6E6E6;
             display: flex;
             justify-content: center;
             align-items: center;
            
             .bordercolor {
                 border: 1px solid #2178F1;
                 background-color: #E7F0FF;
                 color: #2178F1;
             }
             .teshubtn {
                   width: 88px;
             
             }
             .teshu222 {
                   margin-right: 0px !important;
                     padding: 6px 8px !important;
                    //  background-color: #2178F1 !important;
                     border-radius: 4px !important;
                     margin-left: 8px !important;
                     color:#2178F1 !important;
                     background-color: #E7F0FF !important;
                     &:hover{
                        background-color: #E7F0FF !important;
                     }
             }
            
        }
        .qitaxinxi {
            width: calc(100% - 252px);
             right: 12px;
             justify-content: flex-end;
        }
       
     }
  
 }
 .drawer-con {
     width: 100%;
     height: 500px;
     padding: 12px 20px 0px 20px;
     box-sizing: border-box;
     display: flex;
     .left-tree {
         min-width: 192px;
         height: 100%;
         border-right: 1px solid #E6E6E6;
         padding-right: 12px;
         box-sizing: border-box;
         .bottomoperate-btn { 
            width: 88px;
            margin-bottom: 12px;
            margin-top: 8px;
         }
         .custom-tree-node {
            width: 100%;
             display: flex;
             align-items: center;
             justify-content: space-between;
             padding-right: 9px;
             .treeimg {
                 display: none;
             }
             &:hover {
                 .treeimg {
                        display: block;
                    }
             }
            
         }
     }
     .right-table {
         width: calc(100% - 192px);
         height: 100%;
         margin-left: 12px;
         .bottomoperate-btn { 
            width: 88px;
            margin-bottom: 12px;
            margin-top: 8px;
         }
         .table-img {
             display: flex;
             align-items: center;
             justify-content: center;
         }
     }
 }
</style>